/* TESTING FOR AUTOCORRELATION -- AN APPLICATION TO THE CONSUMPTION FUNCTION */ /* LOAD DATA AND DEFINE VARIABLES */ load path = c:\gauss35\classes\econ5340\data\; load x[37,3] = table6.10; t = x[2:37,1]; y = x[2:37,2]; c = x[2:37,3]; nobs = rows(t); constant = ones(nobs,1); xmat = constant~t~y; k = cols(xmat); /* OLS ESTIMATION */ b = inv(xmat'*xmat)*(xmat'*c); resids = c - xmat*b; /* ********************* */ /* AUTOCORRELATION TESTS */ /* ********************* */ /* DURBIN-WATSON TEST */ err = resids[2:nobs,1]; err1 = resids[1:nobs-1,1]; diff = err - err1; dwstat = (diff'*diff)/(resids'*resids); print "Durbin-Watson Statistic = " dwstat; print; /* LAGRANGE MULTIPLIER TEST */ y2 = y[2:nobs,1]; t2 = t[2:nobs,1]; lmcons = constant[2:nobs,1]; lmx = lmcons~y2~t2~err1; alpha = inv(lmx'*lmx)*(lmx'*err); lmresids = err - lmx*alpha; errbar = err - meanc(err)*lmcons; R2 = 1 - (lmresids'*lmresids)/(errbar'*errbar); lmstat = (nobs - 1)*R2; print "LM Statistic = " lmstat; print; /* BOX-PIERCE Q TEST */ r1 = (err'*err1)/(resids'*resids); err = resids[3:nobs,1]; err2 = resids[1:nobs-2,1]; r2 = (err'*err2)/(resids'*resids); Q = nobs*(r1^2 + r2^2); print "Box-Pierce Q Statstic = " Q;