sim_pvarife: Simulate panel VAR data with interactive fixed effects

View source: R/simulate.R

sim_pvarifeR Documentation

Simulate panel VAR data with interactive fixed effects

Description

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 N(1, 1).

Usage

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
)

Arguments

n_units

Positive integer. Number of cross-sectional units I (default 50).

n_time

Positive integer. Number of time periods T after burn-in (default 30).

n_vars

Positive integer. Number of VAR variables K (default 2).

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. "short_run" (default) uses A_0 = \mathrm{chol}(\Sigma_e)^\top; "long_run" uses the Blanchard-Quah impact matrix A_0 = (I - \Theta_1)\,\mathrm{chol}(D)^\top where D = (I-\Theta_1)^{-1}\Sigma_e(I-\Theta_1)^{-\top}. The long-run multiplier C(1) = (I-\Theta_1)^{-1}A_0 = \mathrm{chol}(D)^\top is lower-triangular. Matches the MATLAB GeneratingSynteticDataSets.m with Identification='WithLongRunRestrictions'.

seed

Optional integer seed for reproducibility (default 42).

Details

The data generating process is:

y_{i,t} = c + \Theta_1 y_{i,t-1} + f_t \lambda_i + A_0 \varepsilon_{i,t},

where

\Theta_1 = \begin{pmatrix} 0.65 & 0.30 \\ 0.20 & 0.60 \end{pmatrix}, \quad \Sigma_e = \begin{pmatrix} 1 & 0.5 \\ 0.5 & 1 \end{pmatrix},

f_t = 0.5 f_{t-1} + \eta_t, \; \eta_t \sim N(0, 0.5),

\lambda_{k,i} \sim N(1, 1) \;\text{(independently)},

and A_0 = \mathrm{chol}(\Sigma_e)^\top (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).

Value

A list with:

y

Array of dimension I \times T \times K (unit \times time \times variable). No missing values.

beta_true

True coefficient vector, same format as fit$beta.

theta_true

True VAR coefficient array K \times K \times n\_lags.

sigma_true

True reduced-form covariance matrix K \times K.

a0_true

True structural impact matrix K \times K.

factors_true

T \times n\_factors matrix of true factors.

loadings_true

K \times n\_units matrix of true loadings.

identification

The identification scheme used ("short_run" or "long_run").

diff_vars_suggested

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

Examples

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_true


pvarife documentation built on June 11, 2026, 5:08 p.m.