%% Conduct 1-Step Granger Causality Test Conditioned on Variable
% Assess whether the US gross domestic product (GDP) Granger-causes CPI conditioned on the M1 money supply.
% Load the US macroeconomic data set Data_USEconModel.mat.

load Data_USEconModel

% The variables GDP and GDPDEF of DataTable are the US GDP and its deflator with respect to year 2000 dollars, respectively. Both series are  nonstationary.
%
% Convert the M1 money supply and CPI to rates. Convert the US GDP to the real GDP rate.

m1slrate = price2ret(DataTable.M1SL);
inflation = price2ret(DataTable.CPIAUCSL);
rgdprate = price2ret(DataTable.GDP./DataTable.GDPDEF);

%
% Assume that a VAR(1) model is an appropriate multivariate model for the rates. Conduct a Granger causality test to assess whether the real GDP rate has an impact on the predictive distribution of the inflation rate, conditioned on the M1 money supply. The inclusion of a conditional variable forces gctest to conduct a 1-step Granger causality test.

h = gctest(rgdprate,inflation,m1slrate)

% The test decision h is 0, which indicates failure to reject the null hypothesis that the real GDP rate is not a 1-step Granger-cause of inflation when you account for the M1 money supply rate.
% gctest includes the M1 money supply rate as a response variable in the underlying VAR(1) model, but it does not include the M1 money supply in the computation of the test statistics.
% Conduct the test again, but without conditioning on the M1 money supply rate.

h = gctest(rgdprate,inflation)

% The test result is the same as before, suggesting that the real GDP rate does not Granger-cause inflation at all periods in a forecast horizon and regardless of whether you account for the M1 money supply rate in the underlying VAR(1) model.
% Copyright 2018 The MathWorks, Inc.