lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
362 stars 59 forks source link

Calculating ATT for a given range of post-periods #403

Open kennchua opened 1 year ago

kennchua commented 1 year ago

In the package example for two-way fixed effects and sunab(), we can get the ATT as follows:

data(base_stagg)
res_twfe = feols(y ~ x1 + i(time_to_treatment, treated,
                            ref = c(-1, -1000)) | id + year, base_stagg)
aggregate(res_twfe, c("ATT" = "treatment::[^-]"))

res_sunab = feols(y ~ x1 + sunab(year_treated, year) | id + year, base_stagg)
aggregate(res_sunab, c("ATT" = "year::[^-]"))

How would one approach getting the ATT for a subset of the periods (e.g. 0-3)? I tried the following for TWFE regressions:

aggregate(res_twfe, c("ATT" = "time_to_treatment::(0|1|2|3):treated$"))

But it just returns the estimates for each period rather than an aggregate.

I think it's possible to use something like the marginaleffects::hypotheses() command.

marginaleffects::hypotheses(res_twfe, 
                            paste("(",paste(paste("`", paste("time_to_treatment::", 0:3, ":treated", sep = ""), "`", sep = ""), collapse = "+"), ")/4=0", sep = "")) |>
    broom::tidy()

But in order to do this for output of sunab(), I would need the aggregated variance-covariance matrix.

Would appreciate any leads on how to aggregate effects for a range of post-treatment periods particularly for sunab() regressions.

grantmcdermott commented 1 year ago

Possible duplicate of #295.