*! version 1.0.1 21aug2026

Title

gvar lags -- select the lag orders of each country model

Syntax

gvar lags [, options]

options

maxp(#) largest p considered.

maxq(#) largest q considered.

maxlag(#) sets both when maxp() and maxq() are not given. Default maxlag(2).

ic(string) aic or sbc. Default aic.

psc(#) order of the serial-correlation F test. Default psc(4).

set install the selected orders in the model.

fixed(p [q]) impose these orders on every unit.

detail(unit) print the whole criterion grid for one unit.

nosummary suppress the table.

Description

gvar lags chooses p, the lag order of the domestic block, and
q, that of the foreign block, for each country model, by AIC or SBC over
a grid. It also reports the serial-correlation F test at each candidate so
that a criterion-optimal order that leaves obvious residual autocorrelation is
visible rather than hidden.

With set the chosen orders are written into the model. Without it the
command only reports.

Options

maxlag(#) the maximum order searched, default 2, or set
maxp(#) and maxq(#) separately for the domestic and foreign lags.

Keep these small. The GVAR lag order becomes the maximum over all units of
(p, q), so one unit selecting p = 4 raises the companion matrix for the
whole system -- with K = 136 that is a 544 x 544 eigenvalue problem, and the
extra lags are estimated on 134 observations.

ic(string) the information criterion. psc(#) is the order of the
serial-correlation test reported alongside, default 4, and is the more useful
guide: a criterion minimised at p = 1 while the residuals still show
autocorrelation at that order is not a lag choice you should accept.

fixed(numlist) fixes (p, q) for every unit rather than searching -- one
or two numbers.

set writes the selected orders into the model. Without it the command only
reports.

detail(unit) prints the whole criterion surface for one unit, which is how
you see whether the minimum is sharp or the choice was arbitrary.

nosummary suppresses the report.

Remarks

A caution about the criteria. The Toolbox's AIC and SBC are in
levels form, where larger is better. GVARX reports the log-determinant
form, where smaller is better. Both are computed from the same likelihood; the
sign convention differs. This package follows the Toolbox, so the selected
order is the one with the largest reported criterion.

On the demo. The Toolbox's own demo uses AIC with maximum p = 2 and
q = 1, which is what gvar_demospec.dta encodes.

Examples

. gvar lags, maxlag(2) ic(aic)
. gvar lags, maxp(2) maxq(1) ic(aic) set
. gvar lags, detail(usa)
. gvar lags, fixed(2 1) set

Stored results

gvar lags stores the following in r():

r(lags) the selected orders, one row per unit

r(grid) the criterion grid, with detail()

r(ic) the criterion used

r(maxp) largest p considered

r(maxq) largest q considered

r(p) selected p, with fixed()

r(q) selected q, with fixed()

Source

Toolbox select_varxlag.m, AIC_SBC.m, Ftest_rsc.m.

Author

Dr Merwan Roudane

merwanroudane920@gmail.com

https://github.com/merwanroudane