make_plpr_data: Simulated Data Frame for the 'xtdml' Package

View source: R/dataset.R

make_plpr_dataR Documentation

Simulated Data Frame for the xtdml Package

Description

Generates data from a partially linear panel regression model with fixed effects, following the setting of Clarke and Polselli (2025) but with a tunable data-generating process designed to expose the differences among the panel data approaches implemented in xtdml.

The DGP is defined as

Y_{it} = 1 + \theta_0 D_{it} + g_0(X_{it}) + \alpha_i + U_{it},

D_{it} = m_0(X_{it}) + \gamma_i + V_{it},

where U_{it} and V_{it} are AR(1) idiosyncratic errors with persistence \phi_e and stationary unit variance; \alpha_i is the outcome-side fixed effect; and \gamma_i is the treatment-side fixed effect. The two fixed effects are constructed as

\alpha_i = \sigma_\alpha (\rho F_i + \sqrt{1-\rho^2} E_i),

\gamma_i = \sigma_\gamma \left(\rho_\gamma \frac{\alpha_i}{\sigma_\alpha} + \sqrt{1-\rho_\gamma^2} H_i\right),

where F_i, E_i, H_i \sim \mathcal{N}(0,1) are mutually independent unit-level draws. The parameter \rho controls the correlation between \alpha_i and the individual mean of the covariates \bar{X}_i, while \rho_\gamma controls the correlation between the outcome- and treatment-side fixed effects: \rho_\gamma = 0 corresponds to uncorrelated random effects and \rho_\gamma = 1 to a strict fixed-effects specification.

Covariates follow a unit-level AR(1) process with persistence \phi_x:

X_{it,j} = F_i + \phi_x (X_{i,t-1,j} - F_i) + \eta_{itj}, \quad \eta_{itj} \sim \mathcal{N}(0,1),

initialised from the stationary marginal at t = 1. Higher \phi_x produces more persistent within-unit variation, which preserves signal in the first-differenced covariates and favours the FD-exact approach.

The nuisance functions are smooth polynomial and trigonometric functions of the first four covariates:

m_0(X_{it}) = 0.5 \sin(X_{it,1}) + 0.3 X_{it,2} + 0.1 (X_{it,3}^2 - 1) + 0.15 X_{it,1} X_{it,4},

g_0(X_{it}) = 0.4 \cos(X_{it,1}) + 0.5 X_{it,3} + 0.1 (X_{it,4}^2 - 1) + 0.15 X_{it,2} X_{it,3}.

These forms are smooth (no threshold indicators) and can be recovered by tree-based, penalised, and neural learners at moderate sample sizes.

Usage

make_plpr_data(
  n_obs = 500,
  t_per = 8,
  dim_x = 10,
  theta = 0.5,
  rho = 0.7,
  rho_gamma = 0,
  phi_x = 0.4,
  phi_e = 0,
  sigma_a = 2,
  sigma_g = 1,
  seed = NULL
)

Arguments

n_obs

(integer(1))
The number of cross-sectional units i to simulate. Default is 500.

t_per

(integer(1))
The number of time periods t to simulate. Default is 8. Values below 4 leave too few effective periods per unit under FD.

dim_x

(integer(1))
The total number of covariates. The first four are used in the nuisance functions; any additional columns act as noise covariates. Default is 10.

theta

(numeric(1))
The true value of the structural (causal) parameter \theta_0. Default is 0.5.

rho

(numeric(1))
Correlation between the outcome-side fixed effect \alpha_i and the shared unit-level component F_i of the covariates. Controls the strength of the endogeneity of \alpha_i with respect to \bar{X}_i. Should lie in [0, 1]. Default is 0.7.

rho_gamma

(numeric(1))
Correlation between the treatment-side fixed effect \gamma_i and the outcome-side fixed effect \alpha_i. \rho_\gamma = 0 yields uncorrelated random effects (under which pooled PLR is consistent), and \rho_\gamma = 1 yields a strict fixed-effects setting (under which pooled PLR is inconsistent). Should lie in [0, 1]. Default is 0.

phi_x

(numeric(1))
AR(1) coefficient governing the within-unit persistence of the covariates. Higher values (closer to 1) preserve identifying signal in first-differenced covariates and favour the FD-exact approach. Should lie in [0, 1). Default is 0.4.

phi_e

(numeric(1))
AR(1) coefficient governing the within-unit persistence of the idiosyncratic errors U_{it} and V_{it}. \phi_e = 0 yields IID errors (under which WG and CRE are efficient), while \phi_e \to 1 approaches a random-walk error structure (under which FD is efficient). Should lie in [0, 1). Default is 0.

sigma_a

(numeric(1))
Scale (standard deviation) of the outcome-side fixed effect \alpha_i. Default is 2.

sigma_g

(numeric(1))
Scale (standard deviation) of the treatment-side fixed effect \gamma_i. Default is 1.

seed

(integer(1) or NULL)
Optional integer seed for reproducibility. If NULL (the default), the current state of the random number generator is used.

Value

A data.frame with n_obs * t_per rows and the following columns:

id

unit identifier, integer in \{1, \ldots, n\_obs\}.

time

time identifier, integer in \{1, \ldots, t\_per\}.

⁠X1, X2, ..., X<dim_x>⁠

covariates.

y

outcome variable.

d

treatment variable.

Examples

# Default: uncorrelated random effects, IID errors
df <- make_plpr_data(n_obs = 500, t_per = 8, dim_x = 10,
                     theta = 0.5, rho_gamma = 0, seed = 1234)

# Strict fixed effects with persistent errors: FD-exact should be efficient
df_fd <- make_plpr_data(n_obs = 500, t_per = 8, dim_x = 10,
                        theta = 0.5, rho_gamma = 1,
                        phi_e = 0.8, phi_x = 0.7, seed = 1234)

# Correlated fixed effects, IID errors: pooled PLR is biased; CRE/WG efficient
df_cre <- make_plpr_data(n_obs = 500, t_per = 8, dim_x = 10,
                         theta = 0.5, rho_gamma = 0.5,
                         phi_e = 0, phi_x = 0.4, seed = 1234)


xtdml documentation built on Sept. 2, 2026, 1:07 a.m.