%% Estimate Generalized IRF of VAR Model
% Consider the 4-D VAR(2) model in docid:econ_ug#mw_b768a60b-6d29-45be-9ae9-71800a1720f4. Estimate the generalized IRF of the system for 50 periods.
% Load the Danish money and income data set, then estimate the VAR(2) model.

load Data_JDanish

Mdl = varm(4,2);
Mdl.SeriesNames = DataTable.Properties.VariableNames;
Mdl = estimate(Mdl,DataTable.Series);

%
% Estimate the generalized IRF from the estimated VAR(2) model.

Response = irf(Mdl,"Method","generalized","NumObs",50);

% Response is a 50-by-4-by-4 array representing the generalized IRF of Mdl.
% Plot the generalized IRF of the bond rate when real income is shocked at time 0.

figure;
plot(0:49,Response(:,2,3))
title("IRF of IB When Y Is Shocked")
xlabel("Observation Time")
ylabel("Response")
grid on

% The bond rate fades slowly when real income is shocked at time 0.
% Copyright 2018 The MathWorks, Inc.