/*------------------------------------------------------------------- !! RBSTSE.SET: THIS PROC RETURNS ROBUST COVARIANCE MATRIX FOR REGRESSION IN PRESENCE OF BOTH SERIAL CORRELATION AND CONDITIONAL HETEROSKEDASTICITY USING METHOD OF NEWEY AND WEST USAGE: v=rbstse(resid,x,nwlag,hh); v=robust covariance matrix resid=Tx1 vector of regression residuals x=Tx(K-1) matrix of regressors (no constant) nwlag: obvious hh--1, Does Hansen-Hodrick ----------------------------------------------------------------*/ proc rbstse(resid,x,nwlag,hh) ; local hub,vcvnw,i,t,w,s,ft,nmom,n2 ; @-------------construct ft-----------------@ hub=rows(x); x=ones(hub,1)~x; ft=resid'.*x'; nmom=rows(ft); n2=cols(ft); w=zeros(nmom,nmom) ; t=1; do while t <= n2 ; w = ft[.,t]*ft[.,t]' + w ; t=t+1 ; endo ; s=w; i=1 ; do while i <= nwlag ; w=zeros(nmom,nmom) ; t=1 ; do while t <= n2-i ; w = ft[.,t]*ft[.,t+i]' + w ; t=t+1 ; endo ; if hh==1; s=s+(w+w');else; s = s + (w + w')*(1-(i/(nwlag+1))) ; endif; i=i+1 ; endo ; w=s; vcvnw=inv((x'x)*inv(w)*(x'x)); @ Covariance matrix @ retp(vcvnw) ; endp ; @=============================================================@