## Output of irf() for VAR models when estimation data is in a matrix or a timetable

Hello,

I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.

When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.

Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.

load Data_JDanish

Mdl = varm(4, 2);

Mdl.SeriesNames = DataTable.Properties.VariableNames;

EstMdlMat = estimate(Mdl, Data);

rng(1);

ResponseMat = irf(EstMdlMat);

% "Display the IRF of the bond rate (variable 3, IB) when the log of real

% income (variable 2, Y) is shocked at time 0."

ResponseMat(:, 2, 3).’

EstMdlTab = estimate(Mdl, DataTimeTable);

rng(1);

ResponseTab = irf(EstMdlTab);

% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a

% one-standard-deviation shock on 01-Jul-1974 (period 0) to

% Mdl.SeriesNames(2), which is the variable Y."

ResponseTab.IB_IRF(:, 2).’

Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).

Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.

But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.

Would be nice if someone could shed some light on this.

For the record: I’m using MATLAB R2024a Update 4, the latest version.Hello,

I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.

When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.

Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.

load Data_JDanish

Mdl = varm(4, 2);

Mdl.SeriesNames = DataTable.Properties.VariableNames;

EstMdlMat = estimate(Mdl, Data);

rng(1);

ResponseMat = irf(EstMdlMat);

% "Display the IRF of the bond rate (variable 3, IB) when the log of real

% income (variable 2, Y) is shocked at time 0."

ResponseMat(:, 2, 3).’

EstMdlTab = estimate(Mdl, DataTimeTable);

rng(1);

ResponseTab = irf(EstMdlTab);

% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a

% one-standard-deviation shock on 01-Jul-1974 (period 0) to

% Mdl.SeriesNames(2), which is the variable Y."

ResponseTab.IB_IRF(:, 2).’

Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).

Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.

But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.

Would be nice if someone could shed some light on this.

For the record: I’m using MATLAB R2024a Update 4, the latest version. Hello,

I’m estimating a K-dimensional VAR model and looking at IRFs for structural (orthogonalized shocks) using the Econometrics toolbox, specifically varm(), estimate() and irf(). For orthogonalized shocks, the order of the model variables matters, as does the decomposition method. irf() uses the lower Cholesky decomposition (which is standard in econometrics), meaning that an orthogonalized shock to variable k will only have a contemporaneous effect on variables k, …, K, but not variables 1, …, k-1.

When estimating the model, I can use an array or a (time)table for my observed data, and the output of irf() will then also be an array or (time)table respectively. My question concerns the interpretation of the entries of either return value, specifically which IRFs are found where in the data structures returned. I am finding difficult to make sense of the documentation, and I’m now thinking that the documentation for irf() (alternatively, its code) is wrong for the timetable case.

Here’s a code snippet, based on the Danish data example in the documentation, that will illustrate what I mean. The order of variables in this model is M2, Y, IB, ID, meaning that (say) a shock to Y should influence IB and ID contemporaneously but not M2.

load Data_JDanish

Mdl = varm(4, 2);

Mdl.SeriesNames = DataTable.Properties.VariableNames;

EstMdlMat = estimate(Mdl, Data);

rng(1);

ResponseMat = irf(EstMdlMat);

% "Display the IRF of the bond rate (variable 3, IB) when the log of real

% income (variable 2, Y) is shocked at time 0."

ResponseMat(:, 2, 3).’

EstMdlTab = estimate(Mdl, DataTimeTable);

rng(1);

ResponseTab = irf(EstMdlTab);

% "For example, Tbl.M2_IRF(:,2) is the IRF of M2 resulting from a

% one-standard-deviation shock on 01-Jul-1974 (period 0) to

% Mdl.SeriesNames(2), which is the variable Y."

ResponseTab.IB_IRF(:, 2).’

Here, ReponseMat(:, 2, 3) is (as indicated by the quote in the comment, which is copied verbatim from the documentation page) the IRF of IB after an orthogonalized shock to Y. When estimating the model using data in a timetable, then (as indicated by the second quote, which is also from the documentation), ResponseTab.IB_IRF(:, 2) should be the IRF of IB after an orthogonalized shock to Y, and hence be identical to ResponseMat(:, 2, 3) (possibly up to round-off error).

Except it isn’t. In fact, the first element of ResponseTab.IB_IRF(:, 2) is zero. This suggests to me that when using irf() with data in a timetable, the economic ordering of the variables should be the opposite. This would result if irf() was using the upper Cholesky decomposition in this case.

But there’s no good reason why it should do that. In fact, there is no good reason why the two methods should give different results at all. The easiest explanation (excluding silly mistakes on my part) is that the documentation for the timetable case is wrong, and ResponseTab.IB_IRF(:, 2) should be read as the IRF of variable 2 (Y) after a shock to IB.

Would be nice if someone could shed some light on this.

For the record: I’m using MATLAB R2024a Update 4, the latest version. irf, econometrics, var model, varm, econometrics toolbox, cholesky decomposition, variable ordering, irfs MATLAB Answers — New Questions