py-qte
  • Unconfounded
    • Estimators
    • Benchmarks
  • IV
    • Estimators
    • Instrument Validity
  • Regression Discontinuity
    • Estimators
  • Difference-in-Differences
    • Estimators
    • Aggregating Estimates
  • Reference

On this page

  • Aggregation
  • By Treatment Group
  • By Time Since Treatment
  • Overall
  • References
  • View source
  • Report an issue

Aggregating Estimates

All estimators in qte.distributional_did follow the per-cell approach of Callaway & Sant’Anna 2021: for a treatment group \(g\) and a period \(t\) they construct the counterfactual distribution of that cell and compare it to the observed one. We are often interested in effects above the level of the individual cells. In the py-qte package, besides the cell-level effect estimates, effects by treatment group, by event time and overall effects, all on the treated, are available.

In the following, we demonstrate these aggregations using the mpdta dataset, a description of which can be found here in the context of the Changes-in-Changes (CIC) estimator.

Listing 1 shows the estimation on which our aggregations are based.

Listing 1
from qte.bootstrap import BootstrapConfig
from qte.datasets import load_mpdta
from qte.distributional_did import estimate_changes_in_changes_effects

QS = [0.25, 0.50, 0.75]

# Kept deliberately small so the page builds quickly while the documentation is being iterated on.
BOOTSTRAP = BootstrapConfig(n_iter=50, seed=42, n_workers=4)

panel = load_mpdta().with_columns(pl.col("first.treat").replace(0, float("inf")).alias("group"))

with timer("changes-in-changes"):
    cic = estimate_changes_in_changes_effects(
        panel,
        "lemp",
        "group",
        "year",
        "countyreal",
        qs=QS,
        bootstrap_config=BOOTSTRAP,
    )
[changes-in-changes] 1.64s

Aggregation

Aggregating distributional estimates differs from aggregating means. To get from cell-level means to an aggregation level of choice, it is enough to weight the individual cells by their relative cell sizes. This is not true for the aggregation of quantiles: a sum of cell-size-weighted quantiles generally does not correspond to the quantile of the distribution that corresponds to the aggregation level (for instance, the overall distribution of outcomes under treatment and under no treatment for the treated group). Thus, one first has to construct the aggregate distribution by combining the cell-level distributions (on a common grid) with the appropriate weights; the quantiles of interest are then the quantiles of that aggregate distribution.

By Treatment Group

One effect per treatment group, averaged over that group’s post-treatment periods.

cic.group.tabulate(quantiles=QS)
Table 1

Quantile & Average Treatment Effects
Outcome         : lemp
Estimator       : changes_in_changes
Base period     : universal
Control group   : never_treated
Confidence Lvl  : 0.95
treatment_group Quantile Effect Estimate Std. Error Lower CI Upper CI
Quantile Treatment Effects
2004 0.25 −0.17 0.15 −0.46 0.12
2004 0.50 −0.13 0.10 −0.32 0.06
2004 0.75 −0.04 0.08 −0.19 0.11
2006 0.25 −0.11 0.07 −0.25 0.04
2006 0.50 0.02 0.07 −0.11 0.14
2006 0.75 −0.02 0.09 −0.19 0.16
2007 0.25 −0.03 0.07 −0.16 0.10
2007 0.50 −0.12 0.06 −0.23 0.00
2007 0.75 −0.07 0.06 −0.19 0.05
Average Treatment Effects
2004 - −0.07 0.05 −0.16 0.03
2006 - 0.00 0.03 −0.05 0.05
2007 - −0.02 0.02 −0.06 0.03
show_chart(cic.group.plot(), facet_width=200)
Figure 1: Changes-in-Changes, aggregated by treatment group.

By Time Since Treatment

Effects by event time \(e = t - g\); negative event times are placebo cells.

cic.event_study.tabulate(quantiles=QS)
Table 2

Quantile & Average Treatment Effects
Outcome         : lemp
Estimator       : changes_in_changes
Base period     : universal
Control group   : never_treated
Confidence Lvl  : 0.95
event_study_period Quantile Effect Estimate Std. Error Lower CI Upper CI
Quantile Treatment Effects
-4 0.25 0.02 0.08 −0.13 0.17
-4 0.50 −0.06 0.09 −0.24 0.12
-4 0.75 0.02 0.10 −0.18 0.23
-3 0.25 0.13 0.08 −0.02 0.29
-3 0.50 −0.02 0.07 −0.16 0.12
-3 0.75 0.07 0.07 −0.07 0.21
-2 0.25 0.05 0.08 −0.11 0.22
-2 0.50 0.04 0.05 −0.06 0.14
-2 0.75 0.07 0.06 −0.04 0.18
0 0.25 −0.07 0.05 −0.17 0.03
0 0.50 −0.02 0.05 −0.13 0.08
0 0.75 0.01 0.07 −0.13 0.14
1 0.25 0.03 0.11 −0.18 0.24
1 0.50 −0.04 0.07 −0.18 0.11
1 0.75 −0.15 0.08 −0.30 0.01
2 0.25 −0.26 0.18 −0.60 0.09
2 0.50 −0.09 0.13 −0.35 0.16
2 0.75 −0.08 0.10 −0.27 0.11
3 0.25 −0.19 0.16 −0.50 0.12
3 0.50 −0.20 0.12 −0.43 0.04
3 0.75 −0.09 0.11 −0.31 0.12
Average Treatment Effects
-4 - 0.01 0.03 −0.04 0.06
-3 - 0.03 0.03 −0.02 0.09
-2 - 0.04 0.02 0.00 0.07
0 - −0.01 0.02 −0.04 0.03
1 - −0.03 0.03 −0.09 0.02
2 - −0.13 0.06 −0.24 −0.01
3 - −0.09 0.05 −0.20 0.01
show_chart(cic.event_study.plot(), facet_width=95)
Figure 2: Changes-in-Changes by event time.

Overall

A single effect, weighting treatment groups by their number of counties.

cic.overall.tabulate(quantiles=QS)
Table 3

Quantile & Average Treatment Effects
Outcome         : lemp
Estimator       : changes_in_changes
Base period     : universal
Control group   : never_treated
Confidence Lvl  : 0.95
Quantile Effect Estimate Std. Error Lower CI Upper CI
Quantile Treatment Effects
0.25 −0.10 0.05 −0.20 0.00
0.50 0.00 0.05 −0.10 0.10
0.75 −0.05 0.06 −0.17 0.08
Average Treatment Effects
- −0.02 0.02 −0.05 0.02
show_chart(cic.overall.plot())
Figure 3: Changes-in-Changes, overall aggregation.

References

  1. Callaway, B., & Sant’Anna, P. H. C. (2021). Difference-in-differences with multiple time periods. Journal of Econometrics, 225(2), 200–230. doi:10.1016/j.jeconom.2020.12.001
  • View source
  • Report an issue