Selects the lag length of a VAR (with a constant and, optionally, exogenous
variables) by an information criterion, using vars::VAR(). The result can
be used as the number of lags P of the information set in hetiv(),
proxyiv(), recols() and svariv().
Arguments
- Y
Numeric matrix or data frame (T x N) of endogenous variables.
- X
Numeric matrix or data frame (T x K) of exogenous variables, or
NULL(default).- crit
Character. Information criterion:
"AIC"(default, following Montiel Olea et al., 2025),"HQ","SC"or"FPE".- lag.max
Integer. Largest lag length considered. Default 15.
References
Montiel Olea, J. L., Plagborg-Moller, M., Qian, E. and Wolf, C. K. (2025). Local projections or VARs? A primer for macroeconomists. NBER Macroeconomics Annual, forthcoming.
Examples
if (requireNamespace("vars", quietly = TRUE)) {
set.seed(1)
Y <- matrix(rnorm(400), ncol = 2)
for (t in 2:200) Y[t, ] <- 0.5 * Y[t - 1, ] + Y[t, ]
lag_opt(Y, lag.max = 4)
}
#> [1] 1
