bcallaway11 / did

Difference in Differences with Multiple Periods, website: https://bcallaway11.github.io/did
288 stars 92 forks source link

modelsummary and simple aggregation #118

Open bcallaway11 opened 2 years ago

bcallaway11 commented 2 years ago

Hi! i was wondering if this feature could be incorporated into the AGGTE object class for the 'simple' type of output. I tested it with my own data and with the mpdta from the package, and I was able to use model summary to produce tables for all other types (group, calendar, and dynamic) while 'simple' threw an error. I dont believe that this is a problem with how i created the aggte object with type simple, as it prints outside of the modelsummary statement perfectly fine. I've attached the following chunk of code that should reproduce what I'm talking about.


data(mpdta)
mw.attgt <- att_gt(yname = "lemp",
                   gname = "first.treat",
                   idname = "countyreal",
                   tname = "year",
                   xformla = ~1,
                   data = mpdta,
)
modelsummary(mw.attgt)
mw.dyn <- aggte(mw.attgt, type='dynamic')
modelsummary(mw.dyn) #works
mw.grp <- aggte(mw.attgt, type='group')
modelsummary(mw.grp) #works 
mw.cal <- aggte(mw.attgt, type='calendar')
modelsummary(mw.cal) #works 
mw.simp <- aggte(mw.attgt, type='simple')
print(mw.simp) #works
modelsummary(mw.simp) #doesnt work 

Best, Zahra

Originally posted by @zthab in https://github.com/bcallaway11/did/issues/88#issuecomment-1054654422

bcallaway11 commented 2 years ago

I think that we just need to set up a broom::tidy function that works for the "simple" aggregation. I didn't check, but I think that the comment is right --- this does not currently work. That said, I don't think there is much work to get this going. I'll check / work on it as soon as possible.

rcragun commented 1 year ago

I am not sure if this should be a new issue or part of this issue. tidy seems to partially work on AGGTEobjs with "simple" aggregation, but the confidence intervals are wrong.

Example

library(broom)
library(did)

data("mpdta")

mw.attgt <- att_gt(yname = "lemp",
                   gname = "first.treat",
                   idname = "countyreal",
                   tname = "year",
                   xformla = ~1,
                   data = mpdta,
)
mw.aggte = aggte(mw.attgt, type='simple')

mw.aggte prints

   ATT    Std. Error     [ 95%  Conf. Int.]  
 -0.04        0.0129    -0.0653     -0.0146 *

tidy(mw.aggte) prints

    type    estimate  std.error    conf.low  conf.high point.conf.low point.conf.high
1 simple -0.03995128 0.01291723 -0.01240008 0.03823454    -0.01240008      0.03823454

sessionInfo()

R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] did_2.1.2   broom_1.0.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9        pillar_1.8.1      compiler_4.1.2    ggpubr_0.6.0      BMisc_1.4.5      
 [6] tools_4.1.2       lattice_0.20-45   lifecycle_1.0.3   tibble_3.1.8      gtable_0.3.1     
[11] pkgconfig_2.0.3   rlang_1.1.0       Matrix_1.5-3      DBI_1.1.3         cli_3.6.0        
[16] rstudioapi_0.14   dplyr_1.0.10      generics_0.1.3    vctrs_0.6.1       trust_0.1-8      
[21] DRDID_1.0.4       grid_4.1.2        tidyselect_1.2.0  glue_1.6.2        data.table_1.14.6
[26] R6_2.5.1          rstatix_0.7.2     fansi_1.0.3       carData_3.0-5     tidyr_1.3.0      
[31] purrr_1.0.1       ggplot2_3.4.0     car_3.1-1         magrittr_2.0.3    backports_1.4.1  
[36] scales_1.2.1      assertthat_0.2.1  abind_1.4-5       colorspace_2.0-3  ggsignif_0.6.4   
[41] utf8_1.2.2        munsell_0.5.0