Estimate DiD for a single cohort (g) and a single event time (e).
Source:R/DiD_within_cohort.R
DiDge.Rd
Estimate DiD for a single cohort (g) and a single event time (e).
Usage
DiDge(
inputdata,
varnames,
cohort_time,
event_postperiod,
base_event = -1,
control_group = "all",
return_data = FALSE,
return_ATTs_only = TRUE
)
Arguments
- inputdata
A data.table.
- varnames
A list of the form varnames = list(id_name, time_name, outcome_name, cohort_name), where all four arguments of the list must be a character that corresponds to a variable name in inputdata.
- cohort_time
The treatment cohort of reference.
- event_postperiod
Number of time periods after the cohort time at which to estimate the DiD.
- base_event
This is the base pre-period that is normalized to zero in the DiD estimation. Default is base_event=-1.
- control_group
There are three possibilities: control_group="never-treated" uses the never-treated control group only; control_group="future-treated" uses those units that will receive treatment in the future as the control group; and control_group="all" uses both the never-treated and the future-treated in the control group. Default is control_group="all".
- return_data
If true, this returns the treated and control differenced data. Default is FALSE.
- return_ATTs_only
Return only the ATT estimates and sample sizes. Default is TRUE.
Value
A single-row data.table() containing the estimates and various statistics such as sample size. If return_data=TRUE
, it instead returns a list in which the data_prepost
entry is the previously-mentioned single-row data.table(), and the other argument data_prepost
contains the constructed data that should be provided to OLS.
Examples
# simulate some data
simdata = SimDiD(sample_size=200)$simdata
# define the variable names as a list()
varnames = list()
varnames$time_name = "year"
varnames$outcome_name = "Y"
varnames$cohort_name = "cohort"
varnames$id_name = "id"
# estimate the ATT for cohort 2007 at event time 1
DiDge(simdata, varnames, cohort_time=2007, event_postperiod=1)
#> Cohort EventTime BaseEvent CalendarTime ATTge ATTge_SE Ncontrol Ntreated
#> <num> <num> <num> <num> <num> <num> <int> <int>
#> 1: 2007 1 -1 2008 1.674411 0.2372155 151 49
# change the base period to -3
DiDge(simdata, varnames, base_event=-3, cohort_time=2007, event_postperiod=1)
#> Cohort EventTime BaseEvent CalendarTime ATTge ATTge_SE Ncontrol Ntreated
#> <num> <num> <num> <num> <num> <num> <int> <int>
#> 1: 2007 1 -3 2008 1.519178 0.2446772 151 49
# use only the never-treated control group
DiDge(simdata, varnames, control_group = "never-treated", cohort_time=2007, event_postperiod=1)
#> Cohort EventTime BaseEvent CalendarTime ATTge ATTge_SE Ncontrol Ntreated
#> <num> <num> <num> <num> <num> <num> <int> <int>
#> 1: 2007 1 -1 2008 1.511766 0.2896609 51 49