generateDidData: Generate longitudinal data with staggered treatment

Description Usage Arguments Value Treatment effect formula Default outcome Examples

View source: R/utils.R

Description

Generate longitudinal data with staggered treatment

Usage

1
2
3
4
5
6
7
8
9
generateDidData(
  i,
  t,
  hdfe = TRUE,
  control = TRUE,
  attrition.rate = 0,
  treatment = ~d * (k + 1),
  ig = ~i%%2
)

Arguments

i

Numeric. Number of units

t

Numeric. Number of periods

hdfe

Logical. Should high dimensional fixed effect be added?

control

Logical. Should continuous control be added?

attrition.rate

Numerical. Default is 0. Probability of missing observation.

treatment

one sided formula, default is ~ d * (k + 1). See details.

ig

an optional one sided formula, default is ~ i %% 2. Will be evaluated to define a new variable which can be used in the treatment formula. By default, ig is ~ i %% 2, that is a random unit invariant dummy variable.

Value

a data.table with columns

i

Unit identifier.

t

Calendar time.

g

Time of treatment.

a

Individual fixed effect. ~N(0,1)

b

Time fixed effect. ~N(0,1)

x1

A continuous, normally distributed control. ~N(0,2)

hdfe

A random effect with {i}/50 modalities. ~ N(0,1)

e

Residual. ~ N(0,2)

hdfefactor

A fixed effect of size {i}/50.

k

Relative time to treatment.

d

Dummy variable defined as k >= 0

h

Randomly generated variable at the level of the cohort.

y

Outcome.

true_effect

True average treatment effect on the treated.

Treatment effect formula

By default the treatment effect is ~ d * (k + 1) where d is an internal dummy equal to one if observation is treated and k is the relative time to event. User can define its own formula to create complex treatment and test the model effectiveness.

User has access to the following hidden variables:

Default outcome

The default data generating process is:

y ~ a + b + hdfe + 2*x1 + d * (k + 1) + e

Variable description is available in previous section.

Examples

1
2
dt <- generateDidData(100,10)
head(dt)

CdfInnovLab/didImputation documentation built on Dec. 17, 2021, 1:57 p.m.