%% Estimate VAR(4) Model
% Fit a VAR(4) model to the consumer price index (CPI) and unemployment rate data.
% Load the Data_USEconModel data set.

load Data_USEconModel

%
% Plot the two series on separate plots.

figure;
plot(DataTable.Time,DataTable.CPIAUCSL);
title('Consumer Price Index');
ylabel('Index');
xlabel('Date');
figure;
plot(DataTable.Time,DataTable.UNRATE);
title('Unemployment Rate');
ylabel('Percent');
xlabel('Date');

%
% 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);

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

Mdl = varm(2,4)

% Mdl is a varm model object. All properties containing NaN values correspond to parameters to be estimated given data.
%
% Estimate the model using the entire data set.

EstMdl = estimate(Mdl,[rcpi unrate])

% EstMdl is an estimated varm model object. It is fully specified because all parameters have known values. The description indicates that the autoregressive polynomial is stationary.
%
% Display summary statistics from the estimation.

summarize(EstMdl)

% Copyright 2012 The MathWorks, Inc.