%% Estimate Generalized IRF of VEC Model
% Consider the 4-D VEC(2) model with two cointegrating relations in docid:econ_ug#mw_9ad2b0fa-23d2-44b5-8e39-741684571ef8. Estimate the generalized IRF of the system for 50 periods.
% Load the Danish money and income data set, then estimate the VEC(2) model.

load Data_JDanish

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

%
% Estimate the generalized IRF from the estimated VEC(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

% When real income is shocked, the bond rate reacts and then settles at approximately 0.0032 after 15 periods.
% Copyright 2018 The MathWorks, Inc.
%