did | R Documentation |
Implement the double did estimator and compute the variance via block bootstrap.
did(
formula,
data,
id_unit,
id_time,
design = "did",
is_panel = TRUE,
option = list()
)
formula |
A formula of the following form,
|
data |
A data frame. |
id_unit |
A variable name of unit (e.g., country name, respondent id).
When |
id_time |
A variable name of time (e.g., year). |
design |
The design to be used: either |
is_panel |
A boolean argument.
This argument should be |
option |
A list of the following option parameters:
|
did
returns an object of DIDdesign
class, which is a list of following items:
A table of estimates in the tibble format.
A list of weight information.
The functions 'summary' is used to obtain and print a summary of the results.
## The standard DID design -----------
### (1) panel data
### (2) repeated cross-section data
## (1) panel data --------------------
data(anzia2012)
set.seed(1234)
fit_panel <- did(
formula = lnavgsalary_cpi ~ oncycle | teachers_avg_yrs_exper +
ami_pc + asian_pc + black_pc + hisp_pc,
data = anzia2012,
id_unit = "district",
id_time = "year",
option = list(n_boot = 20, parallel = FALSE)
)
summary(fit_panel)
## (2) repeated cross-section data ---
data(malesky2014)
set.seed(1234)
ff_rcs <- did(
formula = transport ~ treatment + post_treat | factor(city),
data = malesky2014,
id_time = 'year',
is_panel= FALSE,
option = list(n_boot = 20, id_cluster = "id_district", parallel = FALSE)
)
summary(ff_rcs)
## The staggered adoption design ----
data(paglayan2019)
require(dplyr)
paglayan2019 <- paglayan2019 %>%
filter(!(state %in% c("WI", "DC"))) %>%
mutate(id_time = year,
id_subject = as.numeric(as.factor(state)),
log_expenditure = log(pupil_expenditure + 1),
log_salary = log(teacher_salary + 1))
# estimate effects
set.seed(1234)
fit_sa <- did(
formula = log_expenditure ~ treatment,
data = paglayan2019,
id_unit = "id_subject",
id_time = "id_time",
design = "sa",
option = list(n_boot = 20, parallel = FALSE, thres = 1, lead = 0)
)
summary(fit_sa)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.