code_eventtime: Code time-to-event variable

Description Usage Arguments Details Value See Also Examples

View source: R/code_treattime.R

Description

The function constructs a variable measuring the time to treatment given a panel dataset with a time-varying treatment status indicator.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
code_eventtime(
  unit,
  time,
  treat,
  data,
  baseline = NA,
  never = "min",
  always = "max",
  leads = NA,
  lags = NA
)

Arguments

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 treat=1

always

coding for units for which always treat=1

leads

number of leads to include

lags

number of lags to include

Details

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.

Value

A vector measuring time to event in the units of the panel dataset.

See Also

lm

Examples

 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)

sumtxt/dd documentation built on Jan. 3, 2021, 12:39 a.m.