Skip to contents

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. At its heart, aggr_es() is a convenience wrapper around marginaleffects::hypotheses(), which is used to perform the underlying joint hypothesis test.

Usage

aggr_es(
  object,
  rhs = 0,
  period = "post",
  aggregation = c("mean", "cumulative"),
  abbr_term = TRUE,
  ...
)

Arguments

object

A model object of class fixest, where the i() operator has been used to facilitate an "event-study" DiD design. See Examples.

rhs

Numeric. The null hypothesis value. Defaults to 0.

period

Keyword string or numeric sequence. Which group of periods are we aggregating? Can either be one of three convenience strings---i.e., "post" (the default), "prep", or "both"---or a numeric sequence that matches a subset of periods in the data (e.g. 6:8).

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. If FALSE, then the term column will retain the full hypothesis test string as per usual with marginaleffects(). 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.

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))
#>                     term estimate std.error statistic      p.value s.value
#> 1: post-treatment (mean) 3.906554 0.8598576  4.543257 5.539159e-06 17.4619
#>    conf.low conf.high
#> 1: 2.221264  5.591844
# The underlying hypothesis is saved as an attribute
attributes(post_mean)["hypothesis"]
#> $<NA>
#> NULL
#> 

# Other hypothesis and aggregation options
aggr_es(est, aggregation = "cumulative") # cumulative instead of mean effects
#>                           term estimate std.error statistic      p.value
#> 1: post-treatment (cumulative) 19.53277  4.299288  4.543257 5.539158e-06
#>    s.value conf.low conf.high
#> 1: 17.4619 11.10632  27.95922
aggr_es(est, period = "pre")             # pre period instead of post
#>                    term  estimate std.error statistic   p.value  s.value
#> 1: pre-treatment (mean) -1.179871 0.8561964 -1.378037 0.1681917 2.571821
#>     conf.low conf.high
#> 1: -2.857985 0.4982434
aggr_es(est, period = "both")            # pre & post periods separately
#>                     term  estimate std.error statistic      p.value   s.value
#> 1:  pre-treatment (mean) -1.179871 0.8561964 -1.378037 1.681917e-01  2.571821
#> 2: post-treatment (mean)  3.906554 0.8598576  4.543257 5.539159e-06 17.461902
#>     conf.low conf.high
#> 1: -2.857985 0.4982434
#> 2:  2.221264 5.5918440
aggr_es(est, period = 6:8)               # specific subset of periods
#>                           term estimate std.error statistic     p.value s.value
#> 1: periods6:8-treatment (mean) 2.731705 0.9299503  2.937474 0.003308975  8.2394
#>     conf.low conf.high
#> 1: 0.9090361  4.554374
aggr_es(est, rhs = -1, period = "pre")   # pre period with H0 value of 1
#>                    term   estimate std.error  statistic   p.value   s.value
#> 1: pre-treatment (mean) -0.1798707 0.8561964 -0.2100811 0.8336044 0.2625653
#>     conf.low conf.high
#> 1: -1.857985  1.498243
# Etc.