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.
genCoefs(R, T, d, density, eff_size, seed = NULL)An object of class "FETWFE_coefs", which is a list containing:
A numeric vector representing the full coefficient vector after the inverse fusion transform.
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.
The provided number of treated cohorts.
The provided number of time periods.
The provided number of covariates.
The provided seed.
Integer. The number of treated cohorts (treatment is assumed to start in periods 2 to
R + 1).
Integer. The total number of time periods.
Integer. The number of time-invariant covariates. If d > 0, additional terms
corresponding to covariate main effects and interactions are included in beta.
Numeric in (0,1). The probability that any given entry in the initial sparse
coefficient vector theta is nonzero.
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).
(Optional) Integer. Seed for reproducibility.
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:
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\
The full coefficient vector beta is then computed by applying an inverse fusion
transform to theta using internal routines (e.g.,
genBackwardsInvFusionTransformMat() and genInvTwoWayFusionTransformMat()).
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.
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