Newey West Standard Error
Afficher commentaires plus anciens
Please see below my Newey West Standard Error. Somehow its not working as intendet but i have no clue why. The error message of Matlab does not really contain helpful advise.
Can anyone of you identify the error that i made in the Code?
The file should get X and g (145) from my main file. It always says that it might be unbalanced but i dont see any unbalanced term.
function HCsterr = HCse(resid,X,const)
[n,~] = size(X);
if const == 1
X = [ones(n,1),X];
end
g = floor(4*(n/100)^(2/9));
R = sum( arrayfun( @(h) sum(X(h+1:n).*e(h+1:n).*e(1:n-h).*Xprime(1:n-h) + X(1:n-h).*e(1:n-h).e(h+1:n).*Xprime(h+1:n)) / (1 + h/(g+1), 1:g) ));
VCV = (X' * X)^(-1) * ((X' * diag(resid.^2) * X)+R) * (X' * X)^(-1);
% HCSE
HCsterr = sqrt(diag(VCV));
end

%
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!