| Title: | Panel VAR Models with Interactive Fixed Effects |
|---|---|
| Description: | Implements the estimator of Tugan (2021) <doi:10.1093/ectj/utaa021> for panel vector autoregression (VAR) models with interactive fixed effects. Provides joint estimation of VAR coefficients, latent common factors, and factor loadings via an iterative algorithm that alternates between principal component estimation of the factors and least squares estimation of the VAR coefficients, following the approach of Bai (2009) <doi:10.3982/ECTA6135>. Supports impulse response functions under recursive (Cholesky) identification, parametric confidence bands from the joint asymptotic distribution of the estimator (Theorem 2.3), and a classical residual bootstrap for robustness checks. |
| Authors: | Binzhi Chen [aut, cre] (ORCID: <https://orcid.org/0000-0002-5094-7740>) |
| Maintainer: | Binzhi Chen <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.2 |
| Built: | 2026-06-12 12:16:19 UTC |
| Source: | https://github.com/rickchen0910/pvarife |
Computes the asymptotic bias and variance-covariance matrix of
under Theorem 2.3 of Tugan (2021). These quantities are used by
irf_bands to construct parametric confidence bands.
asymptotic_var(fit)asymptotic_var(fit)
fit |
An object of class |
The function computes three components:
The Hessian (Eq. A.4), which accounts
for factor estimation uncertainty via a two-term formula.
The sandwich variance , accumulated
unit by unit.
Two bias terms: (from factor loading
estimation) and (HAC serial correction with bandwidth
).
Notes on MATLAB replication: This implementation deviates from the
original Asymptotic_Distribution_of_beta.m in two places, following
the paper rather than the code:
: the MATLAB accumulation (line 189) uses only the
final value of the loop variable g rather than summing over
as in Eq. (2.56). Corrected here.
: MATLAB uses
, which drops the
within-period cross-variable terms present in
Eq. (2.65). This function computes the per-period outer products of
Eq. (2.65); in simulations this gives (weakly) better
confidence-interval coverage.
A list with:
Bias vector for , of the same length as
fit$beta.
Asymptotic variance-covariance matrix of .
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) avar <- asymptotic_var(fit) cat("Bias:", avar$bias, "\n")sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) avar <- asymptotic_var(fit) cat("Bias:", avar$bias, "\n")
Constructs confidence bands for structural impulse responses via a recursive
residual bootstrap. For each bootstrap replicate, the idiosyncratic residuals
are resampled (by time index, preserving the contemporaneous correlation
across variables), a new panel is generated recursively from the
estimated VAR dynamics and the (fixed) estimated common component, the full
pvarife model is re-estimated, and IRFs are computed. This is
computationally expensive but does not rely on asymptotic approximations.
bootstrap_irf_bands( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), n_boot = 200L, level = 0.95, seed = NULL )bootstrap_irf_bands( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), n_boot = 200L, level = 0.95, seed = NULL )
fit |
An object of class |
n_periods |
Positive integer. Number of IRF horizons. |
shock |
Positive integer. Index of the structural shock (default 1). |
diff_vars |
Integer vector. Variables to cumulate (default none). |
identification |
Character. |
n_boot |
Positive integer. Number of bootstrap replicates (default 200). |
level |
Numeric in (0, 1). Confidence level (default 0.95). |
seed |
Optional integer seed for reproducibility. |
Each bootstrap panel is generated as
where are the estimated coefficients, the common
component is held fixed at its estimate, the
first periods are initialised at the observed data
, and are residuals resampled with
replacement (whole time rows, so the cross-variable correlation is kept).
Because the path is generated recursively, the bootstrap correctly
propagates the VAR dynamics — unlike a fixed-design scheme that reuses the
original lags.
Scope of the bands. Only the idiosyncratic errors are resampled;
the common component and the reduced-form
covariance structure are held at their estimates. The resulting bands
therefore capture idiosyncratic-error uncertainty only and under-cover
when the common factors account for a large share of the variation (as they
do in the simulation design of Tugan 2021). This routine is intended as a
robustness check; for coefficient inference use asymptotic_var
or summary.pvarife_result, and for the paper's IRF bands use
irf_bands.
An object of class "pvarife_bands" with components
irf, lower, upper, level, and
method = "bootstrap".
sim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) bands <- bootstrap_irf_bands(fit, n_periods = 6, n_boot = 20, seed = 42) plot(bands)sim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) bands <- bootstrap_irf_bands(fit, n_periods = 6, n_boot = 20, seed = 42) plot(bands)
Extract coefficients from a pvarife_result
## S3 method for class 'pvarife_result' coef(object, ...)## S3 method for class 'pvarife_result' coef(object, ...)
object |
An object of class |
... |
Ignored. |
Named numeric vector of coefficients.
Computes structural impulse responses from an estimated pvarife_result
using a recursive (lower-triangular Cholesky) identification scheme. The
identification follows the short-run restriction approach of Tugan (2021).
compute_irf( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), bias_correct = FALSE )compute_irf( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), bias_correct = FALSE )
fit |
An object of class |
n_periods |
Positive integer. Number of IRF horizons to compute. |
shock |
Positive integer. Index of the structural shock (1 = first variable in the ordering). Default is 1. |
diff_vars |
Integer vector. Indices of variables for which cumulative
IRFs are reported (e.g., for variables entered in first differences).
Default is |
identification |
Character. Either |
bias_correct |
Logical. If |
The MA representation is computed recursively:
with the convention for .
Short-run identification (default): The impact matrix is the
lower-triangular Cholesky factor of :
.
Long-run identification (Blanchard-Quah type): The long-run
multiplier is constrained
to be lower-triangular. The impact matrix is
where and
.
This identification restricts shock 1 to have no long-run effect on variable 2
(in a 2-variable system). Faithful to IRs_to_Shocks_LR_Identification.m
in the Monte Carlo replication code.
Bias correction: When bias_correct = TRUE, the impact matrix
is evaluated at the bias-corrected coefficient vector
from asymptotic_var. The uncorrected
estimator is used by default (bias_correct = FALSE) for speed; users
who need confidence bands can rely on irf_bands, whose
median is already implicitly bias-corrected.
The impulse response to shock at horizon is
where is the -th standard basis vector.
A matrix of dimension . Row gives
the response of variable to the structural shock at horizons
. The object has class
c("pvarife_irf", "matrix").
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
irf_bands, bootstrap_irf_bands
sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) ir <- compute_irf(fit, n_periods = 8) dim(ir) # 2 x 8 # Long-run identification ir_lr <- compute_irf(fit, n_periods = 8, identification = "long_run", diff_vars = 1L)sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) ir <- compute_irf(fit, n_periods = 8) dim(ir) # 2 x 8 # Long-run identification ir_lr <- compute_irf(fit, n_periods = 8, identification = "long_run", diff_vars = 1L)
Given an estimated pvarife_result and an arbitrary coefficient vector
beta, runs the inner EM loop to extract common factors and factor
loadings. Useful for advanced users (e.g., bootstrap procedures that need
factor estimates at a perturbed beta).
extract_factors(beta, fit, n_in = 10L)extract_factors(beta, fit, n_in = 10L)
beta |
Numeric vector of VAR coefficients (same length as
|
fit |
An object of class |
n_in |
Number of inner iterations (default 10). |
Faithful translation of Inner_Iteration.m from Tugan (2021).
A list with ff (T x r factor matrix) and loadings
(Kr x I loading matrix).
sim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 2) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) ef <- extract_factors(fit$beta * 0.9, fit) dim(ef$ff) # T x rsim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 2) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) ef <- extract_factors(fit$beta * 0.9, fit) dim(ef$ff) # T x r
Constructs confidence bands for structural impulse responses by drawing from the joint asymptotic distribution of the estimator and the common component (Theorem 2.3 of Tugan 2021). This is a parametric simulation, not a residual bootstrap.
irf_bands( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), n_draw = 500L, level = 0.95, seed = NULL )irf_bands( fit, n_periods, shock = 1L, diff_vars = integer(0), identification = c("short_run", "long_run"), n_draw = 500L, level = 0.95, seed = NULL )
fit |
An object of class |
n_periods |
Positive integer. Number of IRF horizons. |
shock |
Positive integer. Index of the structural shock (default 1). |
diff_vars |
Integer vector. Variables to cumulate (default none). |
identification |
Character. |
n_draw |
Positive integer. Number of simulation draws (default 500). |
level |
Numeric in (0, 1). Confidence level (default 0.95). |
seed |
Optional integer seed for reproducibility. |
For each of the n_draw repetitions, the function:
Draws where
and are the estimated bias and variance from
asymptotic_var.
Draws the common component from a normal with
mean and standard deviation
capturing cross-sectional and time-series uncertainty in factor estimation.
Computes the IRF at .
The median and the and
quantiles across draws give the point estimate
and confidence bands.
Scope of the bands. This is a faithful implementation of the band
construction in Tugan (2021) (ConfidenceBandforIRs.m): the bands
propagate uncertainty in the VAR coefficients and in the
estimated common component, but the reduced-form covariance
is recomputed deterministically for each draw and therefore contributes
little draw-to-draw variation. As a result the bands mainly reflect
coefficient (dynamic) uncertainty and under-state uncertainty
in the contemporaneous impact at horizon 0 (which is a function of
alone). Impulse responses are conventionally reported
normalised by the shock's own horizon-0 response (see plot and the
normalise_by_h1 argument), which fixes that element to one. For formal
inference on the coefficients themselves use asymptotic_var or
summary.pvarife_result, whose Wald intervals attain nominal
coverage in simulations.
An object of class "pvarife_bands" with components:
Point estimate (median across draws, bias-corrected),
.
Lower confidence bound, .
Upper confidence bound, .
The confidence level used.
"asymptotic".
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
bootstrap_irf_bands, compute_irf
sim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) bands <- irf_bands(fit, n_periods = 6, n_draw = 100, seed = 42) plot(bands)sim <- sim_pvarife(n_units = 20, n_time = 15, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) bands <- irf_bands(fit, n_periods = 6, n_draw = 100, seed = 42) plot(bands)
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 produces a lag (rows to of the
output receive rows to of x); a negative offset
produces a lead. Unfilled positions are set to NA.
lag_lead_matrix(x, from_lag, to_lag)lag_lead_matrix(x, from_lag, to_lag)
x |
A numeric matrix with |
from_lag |
Integer. The smallest offset to include (may be negative for leads). |
to_lag |
Integer. The largest offset to include (must be |
Faithful translation of lagleadmatrix.m from the replication package
of Tugan (2021).
A matrix with rows and columns. Column block (1-indexed) corresponds to offset
.
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
x <- matrix(1:12, nrow = 4) lag_lead_matrix(x, 1, 2) # two lags lag_lead_matrix(x, -1, 1) # one lead, contemporaneous, one lagx <- matrix(1:12, nrow = 4) lag_lead_matrix(x, 1, 2) # two lags lag_lead_matrix(x, -1, 1) # one lead, contemporaneous, one lag
Plot impulse response bands
## S3 method for class 'pvarife_bands' plot(x, var_names = NULL, normalise_by_h1 = FALSE, ...)## S3 method for class 'pvarife_bands' plot(x, var_names = NULL, normalise_by_h1 = FALSE, ...)
x |
An object of class |
var_names |
Character vector of variable names (optional). |
normalise_by_h1 |
Logical. If |
... |
Ignored. |
A ggplot2 plot object.
Plot impulse response functions
## S3 method for class 'pvarife_irf' plot(x, var_names = NULL, ...)## S3 method for class 'pvarife_irf' plot(x, var_names = NULL, ...)
x |
An object of class |
var_names |
Character vector of variable names (optional). |
... |
Ignored. |
A ggplot2 plot object.
Print method for pvarife_result
## S3 method for class 'pvarife_result' print(x, ...)## S3 method for class 'pvarife_result' print(x, ...)
x |
An object of class |
... |
Ignored. |
Invisibly returns x.
Jointly estimates VAR coefficients , latent common factors
, and factor loadings for a panel vector autoregression
with interactive fixed effects, following the iterative algorithm of
Tugan (2021) based on Bai (2009).
pvarife(y, n_lags, n_factors, n_out = 50L, n_in = 10L, balanced_init = TRUE)pvarife(y, n_lags, n_factors, n_out = 50L, n_in = 10L, balanced_init = TRUE)
y |
A numeric array of dimension |
n_lags |
Positive integer. Lag order |
n_factors |
Positive integer. Number of interactive fixed effects |
n_out |
Positive integer. Number of outer iterations (default 50).
Corresponds to |
n_in |
Positive integer. Number of inner PCA/EM iterations per outer
step (default 10). Corresponds to |
balanced_init |
Logical. If |
The model is
where is a vector of endogenous variables for
unit at time , is an vector of
unobservable common factors, is a unit-specific loading
vector, and is an idiosyncratic error.
The algorithm alternates between:
An inner loop that extracts factors and loadings via PCA (principal components on the residual cross-product matrix) and imputes missing observations (EM step of Bai 2009).
An outer loop that updates via least squares
after projecting out the estimated factors (using ).
An object of class "pvarife_result", which is a list with:
Coefficient vector of length .
The first elements are equation-specific intercepts; the
remaining elements are VAR lag coefficients stacked
as (column-major).
Factor matrix of dimension (one row per
time period; analogous to MATLAB f).
Block-diagonal factor matrix of dimension
, built as .
Matrix of dimension (factor loadings
per unit, stacked by variable).
Reduced-form error covariance matrix ().
Array of residuals (NA at
unobserved positions).
The original input array (used,
e.g., for initial conditions in bootstrap_irf_bands).
Stacked outcome/regressor arrays (
and ).
Pooled outcome/regressor matrices (complete-case rows only).
Integer matrix : 1 = observed, 0 = missing.
Integer vector of length : number of observed
time periods per unit (analogous to MATLAB TC).
Integer vector of length :
(analogous to MATLAB TNC).
Dimensions.
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
Bai, J. (2009). Panel data models with interactive fixed effects. Econometrica, 77(4), 1229–1279.
sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) print(fit)sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) fit <- pvarife(sim$y, n_lags = 1, n_factors = 1, n_out = 5, n_in = 3) print(fit)
A synthetic panel dataset generated from the DGP of Tugan (2021), Section
S10, via sim_pvarife. Provided as a compact example dataset
for vignettes and function examples.
pvarife_simpvarife_sim
A list with the following components:
Numeric array of dimension
(50 units, 30 time periods, 2 variables).
True coefficient vector of length 6 (2 intercepts + 4 VAR lag coefficients).
True VAR coefficient array of dimension
.
True reduced-form covariance matrix
.
True factor matrix of dimension
.
True factor loadings matrix of dimension
.
Generated with sim_pvarife(n_units = 50, n_time = 30, n_vars = 2,
n_lags = 1, n_factors = 1, seed = 42).
Simulated; see sim_pvarife.
Tugan, M. (2021). Panel VAR models with interactive fixed effects. Econometrics Journal, 24, 225–246. doi:10.1093/ectj/utaa021
Generates synthetic panel data from the DGP of Tugan (2021), Section S10,
with a single common factor following an AR(1) process and factor loadings
drawn from .
sim_pvarife( n_units = 50L, n_time = 30L, n_vars = 2L, n_lags = 1L, n_factors = 1L, identification = c("short_run", "long_run"), seed = 42L )sim_pvarife( n_units = 50L, n_time = 30L, n_vars = 2L, n_lags = 1L, n_factors = 1L, identification = c("short_run", "long_run"), seed = 42L )
n_units |
Positive integer. Number of cross-sectional units |
n_time |
Positive integer. Number of time periods |
n_vars |
Positive integer. Number of VAR variables |
n_lags |
Positive integer. VAR lag order (default 1; higher lags use zero coefficient matrices). |
n_factors |
Positive integer. Number of common factors (default 1; each factor has its own AR(1) process and independent loadings). |
identification |
Character. |
seed |
Optional integer seed for reproducibility (default 42). |
The data generating process is:
where
and (Cholesky identification). A
burn-in of 1000 periods is discarded.
For n_vars = 2 and n_lags = 1, the parameters match the MATLAB
GeneratingSynteticDataSets.m (Short-Run identification variant).
A list with:
Array of dimension (unit
time variable). No missing values.
True coefficient vector, same format as fit$beta.
True VAR coefficient array .
True reduced-form covariance matrix .
True structural impact matrix .
matrix of true factors.
matrix of true loadings.
The identification scheme used ("short_run"
or "long_run").
Integer vector: variables that should be
cumulated in compute_irf(). integer(0) for short-run;
1L for long-run (to display cumulative responses, matching the
MATLAB MC code's DifferencedVariables = [1]).
sim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) dim(sim$y) # 30 x 20 x 2 sim$beta_truesim <- sim_pvarife(n_units = 30, n_time = 20, n_vars = 2, n_lags = 1, n_factors = 1, seed = 1) dim(sim$y) # 30 x 20 x 2 sim$beta_true
Summary method for pvarife_result
## S3 method for class 'pvarife_result' summary(object, ...)## S3 method for class 'pvarife_result' summary(object, ...)
object |
An object of class |
... |
Ignored. |
Invisibly returns a list with fit, avar.