%% Response Data Structure
%% Load the data

load Data_USEconModel

%
%% Examine Data Structures

firstperiod = DataTable.Time(1)
lastperiod = DataTable.Time(end)
seriesnames = DataTable.Properties.VariableNames

%
%% Extract Data

Y = DataTable{:,["CPIAUCSL" "UNRATE" "GDP"]};
x = DataTable.GCE;

lastobsresponse = Y(end,:)
lastobspredictor = x(end)

%
%% Identify Missing Data

catdata = [Y x];
whichmissing = any(isnan(catdata),2);
idxmissing = find(whichmissing)
catdata(idxmissing,:)

%
%% Remove Missing Values

Y = Y(~whichmissing,:);
x = x(~whichmissing);

%
%% Partition Data

p = 4;
fh = 8;       
T = size(Y,1);

idxpre = 1:p;
idxest = (p + 1):(T - fh);
idxfor = (T - fh + 1):T;

Y0 = Y(idxpre,:);   % Presample
YF = Y(idxfor,:);   % Forecast sample
Y = Y(idxest,:);    % Estimation sample

xf = x(idxfor);
x = x(idxest);

%
% Copyright 2015 The MathWorks, Inc.