lag_lead_matrix: Build a matrix of lags and/or leads

View source: R/utils.R

lag_lead_matrixR Documentation

Build a matrix of lags and/or leads

Description

Creates a matrix whose columns are lagged or lead copies of the columns of x, for integer offsets from_lag through to_lag. A positive offset k produces a lag (rows k+1 to T of the output receive rows 1 to T-k of x); a negative offset k produces a lead. Unfilled positions are set to NA.

Usage

lag_lead_matrix(x, from_lag, to_lag)

Arguments

x

A numeric matrix with T rows and K columns.

from_lag

Integer. The smallest offset to include (may be negative for leads).

to_lag

Integer. The largest offset to include (must be \ge from_lag).

Details

Faithful translation of lagleadmatrix.m from the replication package of Tugan (2021).

Value

A matrix with T rows and K \times (to\_lag - from\_lag + 1) columns. Column block j (1-indexed) corresponds to offset from\_lag + j - 1.

References

Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/ectj/utaa021")}

Examples

x <- matrix(1:12, nrow = 4)
lag_lead_matrix(x, 1, 2)   # two lags
lag_lead_matrix(x, -1, 1)  # one lead, contemporaneous, one lag


pvarife documentation built on June 13, 2026, 5:06 p.m.