Hey guys,
I would like to set up a linear regression in Mata. Most importantly, I want to use heteroskedasticity-and-autocorrelation-consistent standard errors such as Newey and West standard errors instead of the regular ones.
With regular standard errors this is something like:
Does anybody know how to set this up with Newey and West standard errors instead?
Help is highly appreciated.
Best,
Christopher
I would like to set up a linear regression in Mata. Most importantly, I want to use heteroskedasticity-and-autocorrelation-consistent standard errors such as Newey and West standard errors instead of the regular ones.
With regular standard errors this is something like:
Code:
mata: mata clear mata set matastrict on real rowvector myreg(real matrix Xall) { real colvector y, b, Xy real matrix X, XX y = Xall[.,1] // dependent var is first column of Xall X = Xall[.,2::cols(Xall)] // the remaining cols are the independent variables X = X,J(rows(X),1,1) // add a constant XX = quadcross(X, X) // linear regression Xy = quadcross(X, y) b = invsym(XX) * Xy return(rows(X), b') } end
Help is highly appreciated.
Best,
Christopher
Comment