Learn R Programming

fetwfe (version 1.5.0)

genCoefs: Generate Coefficient Vector for Data Generation

Description

This function generates a coefficient vector beta for simulation studies of the fused extended two-way fixed effects estimator. It returns an S3 object of class "FETWFE_coefs" containing beta along with simulation parameters R, T, and d. See the simulation studies section of Faletto (2025) for details.

Usage

genCoefs(R, T, d, density, eff_size, seed = NULL)

Value

An object of class "FETWFE_coefs", which is a list containing:

beta

A numeric vector representing the full coefficient vector after the inverse fusion transform.

theta

A numeric vector representing the coefficient vector in the transformed feature space. theta is a sparse vector, which aligns with an assumption that deviations from the restrictions encoded in the FETWFE model are sparse. beta is derived from theta.

R

The provided number of treated cohorts.

T

The provided number of time periods.

d

The provided number of covariates.

seed

The provided seed.

Arguments

R

Integer. The number of treated cohorts (treatment is assumed to start in periods 2 to R + 1).

T

Integer. The total number of time periods.

d

Integer. The number of time-invariant covariates. If d > 0, additional terms corresponding to covariate main effects and interactions are included in beta.

density

Numeric in (0,1). The probability that any given entry in the initial sparse coefficient vector theta is nonzero.

eff_size

Numeric. The magnitude used to scale nonzero entries in theta. Each nonzero entry is set to eff_size or -eff_size (with a 60 percent chance for a positive value).

seed

(Optional) Integer. Seed for reproducibility.

Details

The length of beta is given by $$p = R + (T - 1) + d + dR + d(T - 1) + \mathit{num\_treats} + (\mathit{num\_treats} \times d)$$, where the number of treatment parameters is defined as $$\mathit{num\_treats} = T \times R - \frac{R(R+1)}{2}$$.

The function operates in two steps:

  1. It first creates a sparse vector theta of length \(p\), with nonzero entries occurring with probability density. Nonzero entries are set to eff_size or -eff_size (with a 60\

  2. The full coefficient vector beta is then computed by applying an inverse fusion transform to theta using internal routines (e.g., genBackwardsInvFusionTransformMat() and genInvTwoWayFusionTransformMat()).

References

Faletto, G (2025). Fused Extended Two-Way Fixed Effects for Difference-in-Differences with Staggered Adoptions. arXiv preprint arXiv:2312.05985. https://arxiv.org/abs/2312.05985.

Examples

Run this code
if (FALSE) {
  # Generate coefficients
  coefs <- genCoefs(R = 5, T = 30, d = 12, density = 0.1, eff_size = 2, seed = 123)

  # Simulate data using the coefficients
  sim_data <- simulateData(coefs, N = 120, sig_eps_sq = 5, sig_eps_c_sq = 5)
}

Run the code above in your browser using DataLab