%% Inspect Real U.S. GNP Model for Instability
% Apply recursive regressions using nested windows to look for instability in an explanatory model of real GNP for a period spanning World War II.
% Load the Nelson-Plosser data set.

load Data_NelsonPlosser

% The time series in the data set contain annual, macroeconomic measurements from 1860 to 1970. For more details, a list of variables, and descriptions, enter Description in the command line.
%
% Several series have missing data. Focus the sample to measurements from 1915 to 1970. Identify the breakpoint index corresponding to 1945, the end of the war.

span = (1915 <= dates) & (dates <= 1970);
bp = find(dates(span) == 1945);

% Consider the multiple linear regression model
% \texttt{GNPR}_t=\beta_0+\beta_1\texttt{IPI}_t+\beta_2\texttt{E}_t+\beta_3\texttt{WR}_t.
%
% Collect the model variables into a tabular array. Position the predictors in the first three columns, and the response in the last column. Compute the number of coefficients in the model.

Mdl = DataTable(span,[4,5,10,1]);
numCoeff = size(Mdl,2); % Three predictors and an intercept

%
% Estimate the coefficients using recursive regressions, and return separate plots for the iterative estimates. Identify the iteration corresponding to the end of the war.

recreg(Mdl);
bpIter = bp - numCoeff

% By default, recreg forms the subsamples using nested windows. The end of the war (1945) occurs at the 27th iteration.
% All coefficients show some initial, transient instability during the "burn-in" period (see Tip). The plot of WR seems stable since the line is relatively flat. However, the plots of E, IPI, and the intercept (Const) show instability, particularly just after iteration 27.
% Copyright 2012 The MathWorks, Inc.