moderndid.emfx#

moderndid.emfx(result: EtwfeResult, type: str = 'simple', post_only: bool = True, window: tuple[int, int] | None = None) EmfxResult[source]#

Aggregate ETWFE cell-level treatment effects.

Computes weighted averages of the cohort-time ATTs \(\hat{\tau}_{g,t}\) from etwfe into overall, group, calendar-time, or event-study summaries [1]. For a simple overall effect, the weighted average is

\[\hat{\bar{\tau}}_\omega = \sum_g \sum_{t=g}^{T} \hat{\omega}_g \, \hat{\tau}_{g,t}, \qquad \hat{\omega}_g = \frac{N_g}{\sum_{g'} (T - g' + 1) \, N_{g'}},\]

where \(N_g\) is the number of units in cohort \(g\). For event-study aggregation, effects are averaged by exposure time \(e = t - g\) with cohort-share weights within each exposure level,

\[\hat{\tau}_{\omega,e} = \sum_{g=q}^{T-e} \hat{\omega}_{ge} \, \hat{\tau}_{g,\,g+e}, \qquad \hat{\omega}_{ge} = \frac{N_g}{N_q + \cdots + N_{T-e}}.\]

Standard errors are obtained via the delta method using the model’s variance-covariance matrix.

Parameters:
resultEtwfeResult

Output from etwfe.

type{‘simple’, ‘group’, ‘calendar’, ‘event’}, default=’simple’

Aggregation type:

  • "simple": overall weighted average across all post-treatment (g, t) cells

  • "group": average within each treatment cohort g

  • "calendar": average within each calendar time t

  • "event": average within each exposure time e = t - g

post_onlybool, default=True

If True, only include post-treatment cells (t >= g) in aggregation.

windowtuple[int, int] or None, default=None

For event-study aggregation, restrict to event times within [window[0], window[1]].

Returns:
EmfxResult

Aggregated treatment effects with delta-method standard errors.

See also

etwfe

Estimate the saturated ETWFE regression.

aggte

Aggregation for Callaway and Sant’Anna (2021) group-time ATTs.

References

[1]

Wooldridge, J. M. (2025). “Two-Way Fixed Effects, the Two-Way Mundlak Regression, and Difference-in-Differences Estimators.” Empirical Economics.

Examples

In [1]: from moderndid import etwfe, emfx, load_mpdta
   ...: 
   ...: df = load_mpdta()
   ...: mod = etwfe(
   ...:     data=df,
   ...:     yname="lemp",
   ...:     tname="year",
   ...:     gname="first.treat",
   ...:     idname="countyreal",
   ...: )
   ...: 

Simple overall ATT:

In [2]: print(emfx(mod, type="simple"))
==============================================================================
 Aggregate Treatment Effects (Simple Average)
==============================================================================

 Overall ATT:

┌─────────┬────────────┬────────────────────────┐
│     ATT │ Std. Error │ [95% Conf. Interval]   │
├─────────┼────────────┼────────────────────────┤
│ -0.0477 │     0.0123 │ [ -0.0719,  -0.0235] * │
└─────────┴────────────┴────────────────────────┘

------------------------------------------------------------------------------
 Signif. codes: '*' confidence band does not cover 0

------------------------------------------------------------------------------
 Data Info
------------------------------------------------------------------------------
 Control Group:  Not Yet Treated
 Observations:  2500
 Units:  500

------------------------------------------------------------------------------
 Estimation Details
------------------------------------------------------------------------------
 Estimation Method:  Extended TWFE (OLS)

------------------------------------------------------------------------------
 Inference
------------------------------------------------------------------------------
 Significance level: 0.05
 Delta method standard errors
==============================================================================
 Reference: Wooldridge (2021, 2023)

Event-study aggregation by exposure time:

In [3]: print(emfx(mod, type="event"))
==============================================================================
 Aggregate Treatment Effects (Event Study)
==============================================================================

 Overall summary of ATT's based on event-study/dynamic aggregation:

┌─────────┬────────────┬────────────────────────┐
│     ATT │ Std. Error │ [95% Conf. Interval]   │
├─────────┼────────────┼────────────────────────┤
│ -0.0477 │     0.0123 │ [ -0.0719,  -0.0235] * │
└─────────┴────────────┴────────────────────────┘


 Dynamic Effects:

┌────────────┬──────────┬────────────┬────────────────────────────┐
│ Event time │ Estimate │ Std. Error │ [95% Pointwise Conf. Band] │
├────────────┼──────────┼────────────┼────────────────────────────┤
│          0 │  -0.0311 │     0.0132 │ [-0.0569, -0.0052] *       │
│          1 │  -0.0522 │     0.0171 │ [-0.0857, -0.0187] *       │
│          2 │  -0.1361 │     0.0304 │ [-0.1957, -0.0765] *       │
│          3 │  -0.1047 │     0.0329 │ [-0.1693, -0.0401] *       │
└────────────┴──────────┴────────────┴────────────────────────────┘

------------------------------------------------------------------------------
 Signif. codes: '*' confidence band does not cover 0

------------------------------------------------------------------------------
 Data Info
------------------------------------------------------------------------------
 Control Group:  Not Yet Treated
 Observations:  2500
 Units:  500

------------------------------------------------------------------------------
 Estimation Details
------------------------------------------------------------------------------
 Estimation Method:  Extended TWFE (OLS)

------------------------------------------------------------------------------
 Inference
------------------------------------------------------------------------------
 Significance level: 0.05
 Delta method standard errors
==============================================================================
 Reference: Wooldridge (2021, 2023)

Group-level aggregation:

In [4]: print(emfx(mod, type="group"))
==============================================================================
 Aggregate Treatment Effects (Group/Cohort)
==============================================================================

 Overall summary of ATT's based on group/cohort aggregation:

┌─────────┬────────────┬────────────────────────┐
│     ATT │ Std. Error │ [95% Conf. Interval]   │
├─────────┼────────────┼────────────────────────┤
│ -0.0477 │     0.0123 │ [ -0.0719,  -0.0235] * │
└─────────┴────────────┴────────────────────────┘


 Group Effects:

┌───────┬──────────┬────────────┬────────────────────────────┐
│ Group │ Estimate │ Std. Error │ [95% Pointwise Conf. Band] │
├───────┼──────────┼────────────┼────────────────────────────┤
│  2004 │  -0.0846 │     0.0250 │ [-0.1336, -0.0356] *       │
│  2006 │  -0.0183 │     0.0160 │ [-0.0496,  0.0129]         │
│  2007 │  -0.0431 │     0.0179 │ [-0.0782, -0.0080] *       │
└───────┴──────────┴────────────┴────────────────────────────┘

------------------------------------------------------------------------------
 Signif. codes: '*' confidence band does not cover 0

------------------------------------------------------------------------------
 Data Info
------------------------------------------------------------------------------
 Control Group:  Not Yet Treated
 Observations:  2500
 Units:  500

------------------------------------------------------------------------------
 Estimation Details
------------------------------------------------------------------------------
 Estimation Method:  Extended TWFE (OLS)

------------------------------------------------------------------------------
 Inference
------------------------------------------------------------------------------
 Significance level: 0.05
 Delta method standard errors
==============================================================================
 Reference: Wooldridge (2021, 2023)