Existing methods for multiple time periods (e.g., Callaway and Sant’Anna 2021) work well if the number of treated units in each group \(g\) is “large” (>5)
did_data_staggered$log_streams <-log(did_data_staggered$streams+1)# add first period treateddid_data_staggered_G <- did_data_staggered |>filter(treated ==1, week == treat_week) |>select(song_id, G = week_num)did_data_staggered <-left_join(did_data_staggered, did_data_staggered_G,by ="song_id")did_data_staggered$G <-coalesce(did_data_staggered$G, 0)did_data_staggered$id <-as.numeric(did_data_staggered$song_id)set.seed(123)#increase bootstrap for reliability!library(did)mod.csa <-att_gt(yname ="log_streams",tname ="week_num",idname ="id",gname ="G",biters =2000,data = did_data_staggered)
Warning in pre_process_did(yname = yname, tname = tname, idname = idname, : Be aware that there are some small groups in your dataset.
Check groups: 15,16,17,18,19,20,22,24,25,26,27.
Warning in att_gt(yname = "log_streams", tname = "week_num", idname = "id", :
Not returning pre-test Wald statistic due to singular covariance matrix
mod.sunab <-feols(log_streams ~sunab(G, week_num) | id + week_num, data = did_data_staggered )ggiplot(mod.sunab)
References
Callaway, Brantly, and Pedro H. C. Sant’Anna. 2021. “Difference-in-Differences with Multiple Time Periods.”Journal of Econometrics, Themed issue: Treatment effect 1, 225 (2): 200–230. https://doi.org/10.1016/j.jeconom.2020.12.001.
Goodman-Bacon, Andrew. 2021. “Difference-in-Differences with Variation in Treatment Timing.”Journal of Econometrics, Themed issue: Treatment effect 1, 225 (2): 254–77. https://doi.org/10.1016/j.jeconom.2021.03.014.
Rubin, Donald B. 2005. “Causal Inference Using Potential Outcomes: Design, Modeling, Decisions.”Journal of the American Statistical Association 100 (469): 322–31. https://www.jstor.org/stable/27590541.
Sun, Liyang, and Sarah Abraham. 2021. “Estimating Dynamic Treatment Effects in Event Studies with Heterogeneous Treatment Effects.”Journal of Econometrics, Themed issue: Treatment effect 1, 225 (2): 175–99. https://doi.org/10.1016/j.jeconom.2020.09.006.