*! version 3.0.0 *! dickey -- perform Augmented Dickey-Fuller tests for a unit root. *! Sean Becketti, April 1991. program define dickey version 3.0 local varlist "req ex min(1) max(1)" local options "noCons Detail noFindlag Nlags(int 4) Trend *" parse "`*'" if (`nlags'<0) { di in red "nlags() must be > 0" exit 198 } local ifcons = "`cons'"=="" /* is there a constant? */ local dsn "$S_FN" tempfile tmpfile quietly save `tmpfile' capture { keep `varlist' if "`trend'"~="" { tempvar trend gen long `trend' = _n } /* Lag the indicated variable, then difference it and generate lags of the difference. */ local y "`varlist'" lag 1 `y', s(y) dif 1 `y', s(y) if `nlags' { lag `nlags' D.y } /* Run the Dickey-Fuller regressions. */ reg D.y L.y `trend', `options' local nobs = _result(1) local ifc "constant" if ~`ifcons' { local ifc "no constant" } else local ifc "constant" local ift "trend" if "`trend'"=="" { local ift "no trend" } else local ift "trend" noi di in gr _n "(obs=`nobs', `ifc', `ift')" noi di in gr " Lags tau" noi di in gr "-------------" local l = -1 while (`l'<`nlags') { local l = `l' + 1 if (`l'==0) { reg D.y L.y `trend', `options' } else if (`l'==1) { reg D.y L.y LD.y `trend', `options' } else { reg D.y L.y LD.y-L`l'D.y `trend', `options' } local sign = sign(_b[L.y]) test L.y local tau = `sign'*sqrt(_result(6)) noi di in ye %5.0g `l' _skip(3) %5.0g `tau' } if "`findlag'"=="" { noi findlag D.y L.y `trend', /* */ z n(`nlags') `detail' `options' } } local rc=_rc quietly use `tmpfile', clear capture erase `tmpfile' mac def S_FN "`dsn'" error `rc' end