Figure 1: GDP and Gasoline Price
A question that frequently arises in time series analysis is whether or not one economic variable can help forecast another economic variable. For instance, it has been well documented that nearly all of the postwar economic recessions have been preceded by large increases in the price of petroleum. Does this imply that oil shocks cause recessions?
One way to address this question was proposed by Granger (1969) and popularized by Sims (1972). Testing causality, in the Granger sense, involves using F-tests to test whether lagged information on a variable Y provides any statistically significant information about a variable X in the presence of lagged X. If not, then "Y does not Granger-cause X."
There are many ways in which to implement a test of Granger causality. On particularly simple approach uses the autoregressive specification of a bivariate vector autoregression. Assume a particular autoregressive lag length p, and estimate the following unrestricted equation by ordinary least squares (OLS):
Conduct an F-test of the null hypothesis by estimating the following restricted equation also by OLS:
Compare their respective sum of squared residuals.
If the test statistic
is greater than the specified critical value, then reject the null hypothesis that Y does not Granger-cause X.
It is worth noting that with lagged dependent variables, as in Granger-causality regressions, the test is valid only asymptotically. An asymptotically equivalent test is given by
Another caveat is that Granger-causality tests are very sensitive to the choice of lag length and to the methods employed in dealing with any non-stationarity of the time series.
Producing the desired test statistics requires some preliminary data manipulation. Two Citibase data sets are read from the SASHELP library: CITIQTR, from which the variables DATE and GDPQ are kept, and CITIMON, from which DATE and EEGP are kept.
data gdp; set sashelp.citiqtr; keep date gdpq; run; data gp; set sashelp.citimon; keep date eegp; run;
A problem arises from the fact that GDPQ is quarterly gross domestic product, measured in billions of 1987 dollars from 1980:1 to 1991:4, while EEGP is an index, with base year 1987, of monthly retail gas prices from January 1980 to December 1991. In order to use these two series in this analysis, it is necessary for the observations to be of the same frequency. The EXPAND procedure can be used to transform the monthly gas prices observations into quarterly observations and merge them with the GDP data to create a combined data set with quarterly observations. The OBSERVED= option enables you to control the observation characteristics of the input time series and of the output series. In this example, the average of three monthly observations are used to create each quarterly observation. Then, the data are lagged two periods using the LAG function.
proc expand data=gp out=temp from=month to=qtr; convert eegp / observed=average; id date; run; data combined; merge gdp temp; by date; run; data causal; set work.combined; gdpq_1 = lag(gdpq); gdpq_2 = lag2(gdpq); eegp_1 = lag(eegp); eegp_2 = lag2(eegp); run;
After the data are processed, the unrestricted and restricted models are estimated using the AUTOREG procedure and output files are created for the residuals for each regression.
* unrestricted model; proc autoreg data=causal; model gdpq = gdpq_1 gdpq_2 eegp_1 eegp_2; output out=out1 r=e1; /* output residuals */ run; * restricted model; proc autoreg data=out1; model gdpq = gdpq_1 gdpq_2; output out=out2 r=e0; /* output residuals */ run;
These residuals can then be read into vectors in PROC IML and used to calculate the test statistics with matrix algebra.
ods select Iml._LIT1010 Iml.TEST1_P_VAL1 Iml.TEST2_P_VAL2; ods html body='exgran01.htm'; * compute test; proc iml; start main; use out1; read all into e1 var{e1}; close out1; use out2; read all into e0 var{e0}; close out2; p = 2; /* # of lags */ T = nrow(e1); /* # of observations */ sse1 = ssq(e1); sse0 = ssq(e0); * F test; test1 = ((sse0 - sse1)/p)/(sse1/(T - 2*p - 1)); p_val1 = 1 - probf(test1,p,T - 2*p - 1); * asymtotically equivalent test; test2 = (T * (sse0 - sse1))/sse1; p_val2 = 1 - probchi(test2,p); print "IML Result",, test1 p_val1,, test2 p_val2; finish; run; quit; ods html close;
|
Figure 2: Bivariate Granger Causality Test Results
As shown in Figure 2, with p (the number of lags included in the regressions) set equal to two, both test statistics are significant at the 5% level. Thus, it would seem that past values of petroleum prices help to predict GDP.
Ashley, R. (1988), "On the Relative Worth of Recent Macroeconomic Forecasts," International Journal of Forecasting, 4, 363-376.
Ashley, R., Granger, C.W.J., and Schmalensee, R. (1980), "Advertising and Aggregate Consumption: An Analysis of Causality," Econometrica, 48, 1149-1168.
Berndt, E. (1991), The Practice of Econometrics: Classic and Contemporary, New York: Addison-Wesley.
Geweke, J., Meese, R., and Dent, W. (1983), "Comparing Alternative Tests of Causality in Temporal Systems: Analytic Results and Experimental Evidence," Journal of Econometrics, 21, 161-194.
Granger, C.W.J. (1969), "Investigating Causal Relations by Econometric Methods and Cross-Spectral Methods," Econometrica, 34, 424-438.
Hamilton, J. (1994), Time Series Analysis, Princeton, NJ: Princeton University Press.
Sims, C. (1972), "Money, Income and Causality," American Economic Review, 62, 540-552.
Sims, C. (1980), "Macroeconomics and Reality," Econometrica, 48, 1-48.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/*-----------------------------------------------------------------
Example: Bivariate Granger Causality Test
Requires: SAS/ETS, SAS/IML, SAS/GRAPH
Version: 9.0
------------------------------------------------------------------*/
title 'Bivariate Granger Causality Test';
data gdp;
set sashelp.citiqtr;
keep date gdpq;
run;
data gp;
set sashelp.citimon;
keep date eegp;
run;
proc expand data=gp out=temp from=month to=qtr;
convert eegp / observed=average;
id date;
run;
data combined;
merge gdp temp;
by date;
run;
data causal;
set work.combined;
gdpq_1 = lag(gdpq);
gdpq_2 = lag2(gdpq);
eegp_1 = lag(eegp);
eegp_2 = lag2(eegp);
run;
/** Granger Form **/
* unrestricted model;
proc autoreg data=causal;
model gdpq = gdpq_1 gdpq_2 eegp_1 eegp_2;
output out=out1 r=e1; /* output residuals */
run;
* restricted model;
proc autoreg data=out1;
model gdpq = gdpq_1 gdpq_2;
output out=out2 r=e0; /* output residuals */
run;
ods select Iml._LIT1010
Iml.TEST1_P_VAL1
Iml.TEST2_P_VAL2;
ods html body='exgran01.htm';
* compute test;
proc iml;
start main;
use out1;
read all into e1 var{e1};
close out1;
use out2;
read all into e0 var{e0};
close out2;
p = 2; /* # of lags */
T = nrow(e1); /* # of observations */
sse1 = ssq(e1);
sse0 = ssq(e0);
* F test;
test1 = ((sse0 - sse1)/p)/(sse1/(T - 2*p - 1));
p_val1 = 1 - probf(test1,p,T - 2*p - 1);
* asymtotically equivalent test;
test2 = (T * (sse0 - sse1))/sse1;
p_val2 = 1 - probchi(test2,p);
print "IML Result",, test1 p_val1,,
test2 p_val2;
finish;
run;
quit;
ods html close;
* Plot of the two series;
data trans;
set combined;
keep date gdpq eegp;
obs = _n_;
gdpq = (gdpq - 3600)/1400;
eegp = (eegp - 80)/70;
run;
title1 ' GDP and Gasoline Price';
axis1 label=(angle=90 'Gross Domestic Product')
order=(0 to 1 by .142) minor=none major=none offset=(0,0)
value=('3600' '3800' '4000' '4200' '4400' '4600' '4800' '5000');
axis2 label=(angle=90 'Gasoline Price')
order=(0 to 1 by .142) minor=none major=none offset=(0,0)
value=('80' '90' '100' '110' '120' '130' '140' '150');
axis3 label=('Date');
symbol1 color=red interpol=join value=none;
symbol2 color=blue interpol=join value=none;
proc gplot data=trans;
format date year4.;
plot gdpq*date / cframe=ligr
vaxis=axis1 haxis=axis3;
plot2 eegp*date / cframe=ligr
vaxis=axis2;
run;
quit;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Date Modified: | 2017-01-19 15:20:32 |
Date Created: | 2017-01-19 15:04:43 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/ETS | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Pro x64 | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |