program define bayerhanck, eclass version 10.0 local m1 = _N syntax varname(ts numeric) [if] [in] , Rhs(varlist) [Trend(string) Lags(numlist integer max=1 >=0 <`m1') Crit(numlist integer)] marksample touse *------------------------------------------------------------------------------- * This ado-file carries out the Cointegration Test by Bayer and Hanck (2009). * It requires a left-hand side variable and a set of right-hand side variables * to be chosen. The syntax is: bayerhanck lhsvar, rhs(rhsvar). * * - Three trend specifications are possible: "none", "constant", and "trend". * * - lags(numlist) specifies the number of augmentation lags to be used in each * underlying test * * - crit(1 5 10) specifies the critical values to be reported. * * The code then runs as underlying cointegration tests the tests by Johansen, * Engle and Granger, Boswijk, and Banerjee. * For details see: * Christian Bayer and Christoph Hanck (2009): "Combining Non-Cointegration Tests", * METEOR Reseacrh Memorandum 12/2009, Universty of Maastricht * http://edocs.ub.unimaas.nl/loader/file.asp?id=1391 * * The Distributions under the Null of these tests are supplied in the File * NullDistributions.dta, which has to be in the same folder as the .ado file. * * Authors: Christian Bayer, Universität Bonn * Christoph Hanck, Universitaat Maastricht * Version 0.9 * Date: 05 June 2009 * *-------------------------------------------------------------------------------- qui findfile bayerhanck.ado, path(UPDATES;BASE;SITE;.;PERSONAL;PLUS) tempvar ort qui gen `ort'="`r(fn)'" qui replace `ort'=reverse(`ort') qui replace `ort'=substr(`ort',15,.) qui replace `ort'=reverse(`ort') local ortaux=`ort' in 1 *----------------------------------------------------------- * Check Syntax, Define Defaults *----------------------------------------------------------- if "`trend'"=="" { local trend="constant" } if "`lags'"=="" { local lags=1 } if "`trend'"!="none" & "`trend'"!="constant" & "`trend'"!="trend" { di as err "Trend cannot be specified as " as res "`trend'" exit 198 } if "`crit'"=="" { local crit=5 } *---------------------------------------------------------- * Code trendtypes *---------------------------------------------------------- qui { if "`trend'"=="none" { local ending = "if `touse', noc" local trendtype=1 } else if "`trend'"=="constant" { local ending = "if `touse'" local trendtype=2 } else if "`trend'"=="trend" { local ending="if `touse'" tsset local ending=" `r(timevar)' `ending'" local trendtype=3 } mat stat=(0,0,0,0) *------------------------------------------------------- * 1) Run Underlying Tests *------------------------------------------------------- * 1.1) Engle Granger Test *------------------------------------------------------- regress `varlist' `rhs' `ending' tempvar error predict `error', r dfuller `error' if `touse', lags(`lags') nocon mat stat[1,1]=`r(Zt)' drop `error' *------------------------------------------------------- * 1.2) Johansen Test *------------------------------------------------------- local jlags=`lags'+1 vecrank `varlist' `rhs' if `touse', trend(`trend') lags(`jlags') mat aux=e(max) mat stat[1,2]=aux[1,1] local nvar=`e(k_eq)' *------------------------------------------------------- * 1.3) Boswijk / Banerjee Tests *------------------------------------------------------- local Xlag = "`varlist' `rhs'" local Ydif = "d.`varlist'" local W = "d.(`rhs')" if `lags'>=1 { local W = "`W' l.(1/`lags').d.(`Xlag')" } local count=0 foreach rhv in `Xlag' { local count=`count'+1 regress l.`rhv' `W' `ending' tempvar error`count' predict `error`count'', r } regress `Ydif' `W' `ending' tempvar errLHV predict `errLHV', r regress `errLHV' `error1' - `error`count'' `ending' mat betas= e(b) mat var= e(V) mat stat[1,3]=betas[1,1]/sqrt(var[1,1]) mat stat[1,4]=betas*inv(var)*betas' capture drop `error1' - `error`count'' `errLHV' *------------------------------------------------------- * 2) Obtain P-Values *------------------------------------------------------- * 2.1) Load Null-Distribution *------------------------------------------------------- preserve use "`ortaux'NullDistr.dta", clear mat pval=stat local basecase=44*(`trendtype'-1)+4*(`nvar'-2) *--------------------------------------------- * 2.2) Calculate P-Values *--------------------------------------------- forv j=1/4 { local case=`basecase'+`j' if `j'==1 | `j'==3 { count if stat[1,`j']>var`case' mat pval[1,`j']=`r(N)'/_N+.000000000001 } else if `j'==2 | `j'==4 { count if stat[1,`j']