Newey West Standard Error
Ältere Kommentare anzeigen
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

%
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!