| 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). 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.1 |
| Built: | 2026-06-11 18:22:32 UTC |
| Source: | https://github.com/cran/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
).
Note on MATLAB replication: The original Asymptotic_Distribution_of_beta.m
contains a bug at line 189 where the accumulation uses only the
final value of the loop variable g rather than summing over
. This function implements the corrected version.
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 classical
residual bootstrap. For each bootstrap replicate, residuals are resampled
(by time index, preserving cross-sectional dependence), a new panel is
constructed, 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. |
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.
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).
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.