genCoefsCore {fetwfe} | R Documentation |
Generate Coefficient Vector for Data Generation
Description
This function generates a coefficient vector beta
along with a sparse auxiliary vector
theta
for simulation studies of the fused extended two-way fixed effects estimator. The
returned beta
is formatted to align with the design matrix created by
genRandomData()
, and is a valid input for the beta
argument of that function. The
vector theta
is sparse, with nonzero entries occurring with probability density
and
scaled by eff_size
. See the simulation studies section of Faletto (2025) for details.
Usage
genCoefsCore(R, T, d, density, eff_size, seed = NULL)
Arguments
R |
Integer. The number of treated cohorts (treatment is assumed to start in periods 2 to
|
T |
Integer. The total number of time periods. |
d |
Integer. The number of time-invariant covariates. If |
density |
Numeric in (0,1). The probability that any given entry in the initial sparse
coefficient vector |
eff_size |
Numeric. The magnitude used to scale nonzero entries in |
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:
It first creates a sparse vector
theta
of lengthp
, with nonzero entries occurring with probabilitydensity
. Nonzero entries are set toeff_size
or-eff_size
(with a 60\The full coefficient vector
beta
is then computed by applying an inverse fusion transform totheta
using internal routines (e.g.,genBackwardsInvFusionTransformMat()
andgenInvTwoWayFusionTransformMat()
).
Value
A list with two elements:
beta
A numeric vector representing the full coefficient vector after the inverse fusion transform.
theta
A numeric vector that is sparse, from which
beta
is derived.
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
## Not run:
# Set parameters for the coefficient generation
R <- 3 # Number of treated cohorts
T <- 6 # Total number of time periods
d <- 2 # Number of covariates
density <- 0.1 # Probability that an entry in the initial vector is nonzero
eff_size <- 1.5 # Scaling factor for nonzero coefficients
seed <- 789 # Seed for reproducibility
# Generate coefficients using genCoefsCore()
coefs_core <- genCoefsCore(R = R, T = T, d = d, density = density,
eff_size = eff_size, seed = seed)
beta <- coefs_core$beta
theta <- coefs_core$theta
# For diagnostic purposes, compute the expected length of beta.
# The length p is defined internally as:
# p = R + (T - 1) + d + d*R + d*(T - 1) + num_treats + num_treats*d,
# where num_treats = T * R - (R*(R+1))/2.
num_treats <- T * R - (R * (R + 1)) / 2
p_expected <- R + (T - 1) + d + d * R + d * (T - 1) + num_treats + num_treats * d
cat("Length of beta:", length(beta), "\nExpected length:", p_expected, "\n")
## End(Not run)