Aggregates post- (and/or pre-) treatment effects of an
"event-study" estimation, also known as a dynamic difference-in-differences
(DDiD) model. The event-study should have been estimated using the fixest
package, which provides a specialised i()
operator for this class
of models. By default, the function will return the average post-treatment
effect (i.e., across multiple periods). However, it can also return the
cumulative post-treatment effect and can be used to aggregate pre-treatment
effects too.
Arguments
- object
A model object of class
fixest
, where thei()
operator has been used to facilitate an "event-study" DiD design. See Examples.- period
Keyword string or numeric sequence. Which group of periods are we aggregating? Accepts the following convenience strings:
"post"
(the default),"pre"
,"both"
, or"diff
(for the difference between the post and pre periods). Alternatively, can also be a numeric sequence that designates an explicit subset of periods in the data (e.g.6:8
).- rhs
Numeric. The null hypothesis value. Defaults to 0.
- aggregation
Character string. The aggregation type. Either
"mean"
(the default) or"cumulative"
.- abbr_term
Logical. Should the leading "term" column of the return data frame be abbreviated? The default is
TRUE
. IfFALSE
, then the term column will retain the full hypothesis test string as per usual withmarginaleffects::hypotheses()
. Note that this information is retained as an attribute of the return object, regardless.- ...
Additional arguments passed to
marginaleffects::hypotheses()
.
Value
A "tidy" data frame of aggregated (pre and/or post) treatment effects, plus inferential information about standard errors, confidence intervals, etc. Potentially useful information about the underlying hypothesis test is also provided as an attribute. See Examples.
See also
marginaleffects::hypotheses()
, which this function is ultimately a
convenience wrapper around.
Examples
library(ggfixest) ## Will load fixest too
est = feols(y ~ x1 + i(period, treat, 5) | id + period, base_did)
# Default hypothesis test is a null mean post-treatment effect
(post_mean = aggr_es(est))
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> 3.91 0.86 4.54 <0.001 17.5 2.22 5.59
#>
#> Term: post-treatment (mean)
#>
# The underlying hypothesis is saved as an attribute
attr(post_mean, "hypothesis")
#> post
#> "(`period::6:treat` + `period::7:treat` + `period::8:treat` + `period::9:treat` + `period::10:treat`)/5 = 0"
# Other hypothesis and aggregation options
aggr_es(est, period = "pre") # pre period instead of post
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> -1.18 0.856 -1.38 0.168 2.6 -2.86 0.498
#>
#> Term: pre-treatment (mean)
#>
aggr_es(est, period = "both") # pre & post periods separately
#>
#> Term Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> pre-treatment (mean) -1.18 0.856 -1.38 0.168 2.6 -2.86 0.498
#> post-treatment (mean) 3.91 0.860 4.54 <0.001 17.5 2.22 5.592
#>
#>
aggr_es(est, period = "diff") # post vs pre difference
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> 5.09 0.472 10.8 <0.001 87.5 4.16 6.01
#>
#> Term: difference (post vs pre mean)
#>
aggr_es(est, period = 6:8) # specific subset of periods
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> 2.73 0.93 2.94 0.00331 8.2 0.909 4.55
#>
#> Term: periods 6:8 (mean)
#>
aggr_es(est, period = "pre", rhs = -1) # pre period with H0 value of 1
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> -0.18 0.856 -0.21 0.834 0.3 -1.86 1.5
#>
#> Term: pre-treatment (mean)
#>
aggr_es(est, aggregation = "cumulative") # cumulative instead of mean effects
#>
#> Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
#> 19.5 4.3 4.54 <0.001 17.5 11.1 28
#>
#> Term: post-treatment (cumulative)
#>
# Etc.