Learn R Programming

ggfixest (version 0.3.0)

aggr_es: Aggregates event-study treatment effects.

Description

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.

Usage

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

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.

Arguments

object

A model object of class fixest, where the i() 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. If FALSE, then the term column will retain the full hypothesis test string as per usual with marginaleffects::hypotheses(). Note that this information is retained as an attribute of the return object, regardless.

...

Additional arguments passed to marginaleffects::hypotheses().

See Also

marginaleffects::hypotheses(), which this function is ultimately a convenience wrapper around.

Examples

Run this code
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))

# The underlying hypothesis is saved as an attribute
attr(post_mean, "hypothesis")

# Other hypothesis and aggregation options
aggr_es(est, period = "pre")             # pre period instead of post
aggr_es(est, period = "both")            # pre & post periods separately
aggr_es(est, period = "diff")            # post vs pre difference
aggr_es(est, period = 6:8)               # specific subset of periods
aggr_es(est, period = "pre", rhs = -1)   # pre period with H0 value of 1
aggr_es(est, aggregation = "cumulative") # cumulative instead of mean effects
# Etc.

Run the code above in your browser using DataLab