%% Specify Presample Values
% Fit a VAR(4) model to the consumer price index (CPI) and unemployment rate data. The estimation sample starts at Q1 of 1980.
% Load the Data_USEconModel data set.

load Data_USEconModel

%
% Stabilize the CPI by converting it to a series of growth rates. Synchronize the two series by removing the first observation from the unemployment rate series.

rcpi = price2ret(DataTable.CPIAUCSL);
unrate = DataTable.UNRATE(2:end);

%
% Identify the index corresponding to the start of the estimation sample.

estIdx = DataTable.Time(2:end) > '1979-12-31';

%
% Create a default VAR(4) model using the shorthand syntax.

Mdl = varm(2,4);

%
% Estimate the model using the estimation sample. Specify all observations before the estimation sample as presample data. Display a full estimation summary.

Y0 = [rcpi(~estIdx) unrate(~estIdx)];
EstMdl = estimate(Mdl,[rcpi(estIdx) unrate(estIdx)],'Y0',Y0,'Display',"full");

% Because the VAR model degree p is 4, estimate uses only the last four observations in Y0 as a presample.
% Copyright 2012 The MathWorks, Inc.