%% Address Integrated Series During Testing
% If you are testing integrated series for Granger causality, then the Wald test statistic does not follow a \chi^2 or F distribution, and test results can be unreliable. However, you can implement the Granger causality test in docid:econ_ug#mw_8d76bb2d-c280-49d2-844b-204fbfe95ecd by specifying the maximum integration order among all the variables in the system using the 'Integration' name-value pair argument.
% Consider the Granger causality tests conducted in docid:econ_ug#mw_2703a82b-4f23-4d30-a8db-9a70804b12bf. Load the US macroeconomic data set Data_USEconModel.mat and take the log of real GDP and CPI.

load Data_USEconModel
cpi = log(DataTable.CPIAUCSL);
rgdp = log(DataTable.GDP./DataTable.GDPDEF);

%
% Assess whether the real GDP Granger-causes CPI. Assume the series are I\left(1\right), or order-1 integrated. Also, specify an underlying VAR(3) model and the F test. Return the test statistic and p-value.

[h,pvalue,stat] = gctest(rgdp,cpi,'NumLags',3,...
    'Integration',1,'Test',"f")

% The p-value = 0.0031, indicating the existence of strong evidence to reject the null hypothesis of noncausality, that is, that the three real GDP lags in the CPI equation are jointly zero.  Given the VAR(3) model, there is enough evidence to suggest that real GDP Granger-causes at least one future value of the CPI.
% In this case, the test augments the VAR(3) model with an additional lag. In other words, the model is a VAR(4) model.  However, gctest tests only whether the first three lags are 0.
% Copyright 2018 The MathWorks, Inc.