Skip to contents

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().

Usage

lag_opt(Y, X = NULL, crit = "AIC", lag.max = 15)

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.

Value

Integer. The lag length selected by the criterion.

Details

Requires the vars package, which is not installed automatically with hetiv.

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