Reduced-form VARs
Practicum · Session 01
Run the monthly model
Obtain the archived input described in the session README and open MATLAB in the repository root. The code below keeps package functions available for the checks after the dispatcher restores its temporary session path.
% Start from the repository root, not from the directory of an individual lecture.
projectRoot = pwd;
% Preserve the original package search path for cleanup after the walkthrough.
originalPath = path;
% Restore the user's path when this cleanup object is cleared.
pathCleanup = onCleanup(@()path(originalPath));
% Make the shared, namespaced estimators available after run_session returns.
addpath(fullfile(projectRoot,'matlab'));
% Fit the preferred monthly VAR and retain both lag-selection conventions.
result = run_session(1);The five columns are production growth, CPI inflation, unemployment, the funds rate, and NFCI. Check this ordering before interpreting any coefficient or constructing a structural shock. The full transformed window has 635 rows, while the preferred VAR(3) has 632 fitted residuals.
% Inspect the sample boundaries on the original transformed monthly calendar.
disp(result.data.dates([1,end]));
% Verify that three initial lags leave 632 usable dependent observations.
assert(result.model.T==632 && result.model.p==3);
% Read every candidate criterion instead of relying only on a selected lag number.
disp(result.selection.table);
% Compare AIC, BIC, and HQ selections under the two explicit sample conventions.
disp([result.selection.orders;result.classroomSelection.orders]);The first fitted design row contains an intercept followed by all five variables at lag one, then lag two, then lag three. A coefficient in row two of the first equation is the own-lag production coefficient. Row seven begins the second lag block; it is not the first lag of variable six.
% Read the first fitted monthly observation and its three complete lag blocks.
disp(result.model.X(1,:));
% The stored autoregressive matrix must transpose the first coefficient block.
assert(max(abs(result.model.A(:,:,1)-result.model.beta(2:6,:)'),[],'all')<1e-12);
% Require all fitted companion roots to be inside the unit circle.
assert(max(abs(result.model.roots))<1);
% Display the first three monthly conditional mean forecasts in transformed units.
disp(result.forecast(1:3,:));Compare with the classroom calculation
The public code does not require original helper functions. For the optional benchmark, supply the original konstantin-session_1 directory to the comparison function documented in the README. It verifies five file hashes before executing them. Its saved table compares all twenty lag orders, not just the BIC winner.
To test a calendar gap without modifying the archived file, use a copy of the transformed arrays. The removed month must also invalidate any regression row that requires it as a lag.
% Copy the monthly observations, leaving the saved replication input untouched.
Ygap = result.data.Y;
% Copy their integer-month calendar labels.
periodGap = result.data.periods;
% Remove only observation one hundred from the temporary arrays.
Ygap(100,:) = [];
% Remove its date as well, so the next row is not mislabeled as the missing month.
periodGap(100) = [];
% Refit a three-lag model with the explicit calendar gap.
gapModel = tsma.var.fit(Ygap,periodGap,3);
% Besides the removed outcome, three later outcomes lose a required lag.
assert(gapModel.T==result.model.T-4);
% Export the checked lag-selection figure and numerical table for the notes.
tsma.var.publish_session(result,projectRoot);
% Restore the original MATLAB path before leaving the walkthrough.
clear pathCleanup;The gap check is a controlled test, not a new empirical specification. Do not overwrite the real input with the temporary gap data.
Worked exercises
The solutions below derive the same design ordering, forecast recursion, and criterion penalties used by the replication.
The first design row
The dependent dates are 3, 4, and 5. Intercept-first, lag-major ordering gives
X=\begin{pmatrix}1&3&1&1&2\\1&2&4&3&1\\1&5&3&2&4\end{pmatrix}, \qquad Y=\begin{pmatrix}2&4\\5&3\\4&6\end{pmatrix}.
There are only three usable observations but k=1+2\cdot2=5 coefficients per equation. X cannot have full column rank; computing a pseudoinverse would not create identification or positive residual degrees of freedom. The production estimator correctly rejects this specification.
After removing date 3, date 4 lacks its first lag and date 5 lacks its second lag. Dates 1 and 2 do not have the required two-period history. No dependent date is usable. Shifting the remaining rows would incorrectly treat date 2 as date 3’s replacement. This is why the lag function matches calendar labels.
Two forecasts
The first forecast uses the observed y_T:
\widehat y_{T+1\mid T}= \begin{pmatrix}1\\0\end{pmatrix}+ \begin{pmatrix}.5&.2\\0&.4\end{pmatrix} \begin{pmatrix}2\\5\end{pmatrix} =\begin{pmatrix}3\\2\end{pmatrix}.
The second step substitutes that forecast, not the original state:
\widehat y_{T+2\mid T}= \begin{pmatrix}1+.5(3)+.2(2)\\.4(2)\end{pmatrix} =\begin{pmatrix}2.9\\.8\end{pmatrix}.
The triangular matrix has eigenvalues .5 and .4, both inside the unit circle. Solve (I-A)\mu=c. The second equation gives .6\mu_2=0, so \mu_2=0; the first gives .5\mu_1-.2\mu_2=1, so \mu_1=2. As a check, forecasts converge toward (2,0)'.
An innovation b=(0,1)' instead has impact response b and one-step response Ab=(.2,.4)'. The intercept cancels when subtracting the no-shock path from the shock path. Thus the forecast (3,2)' and the response (.2,.4)' answer different questions even though both use the same matrix A.
Comparing information criteria
At one lag, each of two equations has three coefficients, hence six system coefficients. At two lags, each has five, hence ten. The criteria are
\begin{aligned} AIC(1)&=-2+2(6)/100=-1.88,\\ AIC(2)&=-2.1+2(10)/100=-1.90,\\ BIC(1)&=-2+\log(100)(6)/100\simeq-1.72369,\\ BIC(2)&=-2.1+\log(100)(10)/100\simeq-1.63948. \end{aligned}
AIC selects two lags; BIC selects one. The second lag lowers the fit term by .1. That exceeds AIC’s extra penalty of .08 but not BIC’s extra penalty of about .18421. This arithmetic is more informative than saying one criterion is always better.
If the larger model loses ten additional observations, its fit term refers to a different set of outcomes. A better score may reflect which observations were removed as well as a better lag specification. Re-estimate both candidates on their common dependent dates before applying the comparison. The data can still be used in full after selecting the order, provided that refit is recorded separately.