%% Choose the Number of Lagged Difference Terms to Include in the Augmented Model
% Test a time series for a unit root against trend-stationary alternatives augmented with different numbers of lagged difference terms. Look at the regression statistics corresponding to each of the alternative models to choose how many lagged difference terms to include in the augmented model.
% Load a time series of GDP data, and calculate its log.

load Data_GDP;
Y = log(Data);

%
% Test for a unit root using three different choices for the number of lagged difference terms. Return the regression statistics for each alternative model.

[h,~,~,~,reg] = adftest(Y,'model','TS','lags',0:2);

% adftest treats each of the three lag choices as separate tests, and returns results for each test. reg is an array of three data structures, corresponding to each alternative model.
%
% Display the names of the coefficients included in each of the three alternatives.

reg.names

% The output shows which terms are included in the three alternative models. The first model has no added difference terms, the second model has one difference term (b1), and the third model has two difference terms (b1 and b2).
%
% Display the t-statistics and corresponding p-values for each coefficient in the three alternative models.

[reg(1).tStats.t reg(1).tStats.pVal]
[reg(2).tStats.t reg(2).tStats.pVal]
[reg(3).tStats.t reg(3).tStats.pVal]

% The returned t-statistics and p-values correspond to the coefficients in reg.names. These results indicate that the coefficient on the first difference term is significantly different from zero in both the second and third models, but the coefficient on the second term in the third model is not. This suggests augmenting the model with one lagged difference term is adequate.
%
% Compare the BIC for each of the three alternatives.

reg.BIC

% Based on the BIC values, choose the model augmented with one lagged difference term because it has the best (that is, the smallest) BIC value.
% Copyright 2015 The MathWorks, Inc.