* * GRANGERBOOTSTRAP.RPF * Bootstrap alternative to CAUSAL.RPF. * cal(m) 1959:1 allocate 2006:4 open data haversample.rat data(format=rats) / gdph fm1 log gdph log fm1 * * Test for unit roots * @dfunit(det=trend,lags=8,method=gtos) gdph @dfunit(det=trend,lags=8,method=gtos) fm1 * * Granger causality test with bootstrapped p-value. * * The bootstrap draws are conditional on the first 8 values of the two * series. We do the equations in terms of "sample" series to make the * bookkeeping easier later on. * * The bootstrapping has to be done under the null, so the GDP equation * is estimated using only the lags of GDP. The money equation uses lags * of both. * set msample = fm1 set gsample = gdph linreg(define=eqg) gsample / rg # constant gsample{1 to 8} linreg(define=eqm) msample / rm # constant gsample{1 to 8} msample{1 to 8} * group noncausal eqg eqm * compute ndraws=10000 set stats 1 ndraws = 0.0 do draw=1,ndraws * * Resample the residuals over the regression range * boot entries %regstart() %regend() set rgsample = rg(entries(t)) set rmsample = rm(entries(t)) * * Rebuild the data using the estimated model and the resampled residuals * forecast(paths,model=noncausal,from=%regstart(),to=%regend(),results=results) # rgsample rmsample set gsample = results(1) set msample = results(2) * * Do the causality test on the resampled data. Except for minor scale * factors, this will give identical results to a full system LR test * (under the assumptions of homoscedasticity). * linreg(noprint) gsample # constant gsample{1 to 8} msample{1 to 8} exclude(noprint) # msample{1 to 8} compute stats(draw)=%cdstat end do draw * * Compute the percentiles of the test statistics * stats(fractiles) stats 1 ndraws * * Do the test with the real data * linreg(noprint) gdph # constant gdph{1 to 8} fm1{1 to 8} exclude(print,title="Granger causality test on original data") # fm1{1 to 8} * * Figure out the bootstrapped p-value * sstats(mean) 1 ndraws (stats>%cdstat)>>pvalue * disp "Bootstrapped p-value" pvalue * * Granger causality test on differenced data. If the series aren't * cointegrated (and there is no reason to believe that they would be), * this wouldn't be misspecified and would have standard asymptotics. * set dgdp = gdph-gdph{1} set dfm1 = fm1-fm1{1} * linreg dgdp # constant dgdp{1 to 7} dfm1{1 to 7} exclude(title="Granger causality test on differenced data") # dfm1{1 to 7}