Description Usage Arguments Details Value See Also Examples
View source: R/code_treattime.R
The function constructs a variable measuring the time to treatment given a panel dataset with a time-varying treatment status indicator.
1 2 3 4 5 6 7 8 9 10 11 |
unit |
unquoted variable name identifying the unit of the panel |
time |
unquoted variable name indicating the ordering of the observations |
treat |
unquoted variable name of the binary treatment status variable |
data |
data frame that includes the variables |
baseline |
baseline or reference period for leads/lags |
never |
coding for units for which never |
always |
coding for units for which always |
leads |
number of leads to include |
lags |
number of lags to include |
The output of this function is a factor variable. When passed to a standard fitting function, the factor variable is broken into dummies encoding leads and lags.
Most fitting functions are using the first level of a factor variable as a reference category.
This means that the first lead serves as the reference period. This can be changed
by setting a value for the parameter baseline
, e.g. -1 to use the last lead before the treatment as reference period.
To exclude units that never receive treatment or that received treatment
before the first period (i.e. for which the treatment status has no
variance), set the parameters always
and never
to NA
. The estimation sample is then limited to the
switcher population.
To accumulate lags and leads set the parameters leads
and lags
to a value that is less than the maximum of
feasible leads/lags.
A vector measuring time to event in the units of the panel dataset.
lm
1 2 3 4 5 6 7 8 9 10 11 12 | library(dd)
data(goldendawn)
goldendawn$t <- code_eventtime(
unit=muni,
time=year,
treat=post,
data=goldendawn)
m <- lm(gd ~ t + factor(muni) + factor(year), data=goldendawn)
summary(m)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.