@========================================================@ @::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @ @ !! ADF(Y,ADFLAG): This proc computes @ @ 1. Studentized coefficient for ADF test of unit root, no trend @ @ 2. Studentized coefficient for ADF test of unit root, with trend @ @ @ @ ALL TESTS INCLUDE A CONSTANT @ @ for no trend results consult Hamilton table B.6, case 2 @ @ for trend results, consult Hamilton table B.6, case 3 @ @ @ @ USAGE: {tau_c,tau_ct} = ADF(Y,ADFLAG) @ @ Y: The data to be analyzed. Null is that Y has a unit root @ @ ADFLAG: Lags to put in the ADF regression @ @ :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @ proc(2)= adf(y,adflag) ; local sig,sigsq,talpha,lam1,lam2,mbaryy,ztau,ft,nmom,n2,w,s,t, ser,a2,tau,sto,nobs,ser,varreg,resid,phi,i,j,k,t0,t1,dy,x, myy,mty,my,m,zalpha,c3,tau_c,tau_ct; t1=rows(y); dy=zeros(t1,1); dy[2:t1,1]=y[2:t1,1]-y[1:t1-1,1]; @ First difference @ j=adflag+2; @ CONSTRUCT X MATRIX FOR ADF REGRESSION--NO TREND @ x=ones(rows(y[j:t1,1]),1)~y[j-1:t1-1,1]~dy[j-1:t1-1,1]; k=2; do while k <= adflag; x=x~dy[j-k:t1-k,1]; k=k+1; endo; nobs=rows(x); @ RUNNING THE ADF REGRESSION @ phi=inv(x'x)*x'*dy[j:t1,1]; resid=dy[j:t1,1]-x*phi; @ ADF regression residuals @ varreg=(resid'*resid)/(nobs-cols(x)); ser=sqrt(varreg); @ Std. Error of regression @ sto=varreg*inv(x'x); tau=phi[2,1]/sqrt(sto[2,2]); tau_c=tau; @ "ADF t-stat for Unit Root (No Trend)";;tau;; adflag;;" Lags";@ @====================================================@ j=adflag+2; @ CONSTRUCT X MATRIX FOR ADF REGRESSION--WITH TREND @ x=ones(rows(y[j:t1,1]),1)~y[j-1:t1-1,1]~dy[j-1:t1-1,1] ~(seqa(1,1,nobs)-nobs/2); k=2; do while k <= adflag; x=x~dy[j-k:t1-k,1]; k=k+1; endo; phi=inv(x'x)*x'dy[j:t1,1]; @ Run the ADF regression @ resid=dy[j:t1,1]-x*phi; @ ADF regression residuals @ varreg=(resid'*resid)/(nobs-cols(x)); ser=sqrt(varreg); @ Std. Error of regression @ sto=varreg*inv(x'x); tau=(phi[2,1])/sqrt(sto[2,2]); tau_ct=tau; @"ADF t-stat for Unit Root (With Trend) ";;tau;; adflag;;" Lags";@ @-------------------------------------------------------------@ retp(tau_c,tau_ct); endp; @=============================================================@