Skip to main content

9.5. Modern Heterogeneity-Robust Staggered Difference-in-Differences

Verified Environments & Platforms:EcoDataEcoLabFincoVietLOD

Methodological Part 9.5. Modern Heterogeneity-Robust Staggered Difference-in-Differences in 9. Causal Inference and Modern Policy Evaluation provides step-by-step How-To implementation guides for 15 econometric model lessons spanning from Section 9.5.1 to 9.5.15. Full theoretical derivations are available at VietLOD Part 9.5 alongside cloud execution on EcoLab.

Video Tutorial: How-To Guide for Part 9.5: Modern Heterogeneity-Robust Staggered Difference-in-Differences in Stata 18, R 4.x, and Python 3.11+

9.5.1. Methodological Overview and Structural Equations​

  • Methodological Focus: Provides consistent estimation and robust inference for Modern Heterogeneity-Robust Staggered Difference-in-Differences specifications within Causal Inference and Modern Policy Evaluation.
  • Mandatory Post-Estimation Diagnostics: Tổng tỷ trọng và ước lượng DID trung bình theo 3 nhóm, tỷ phần trọng số bị ô nhiễm động học..

Core structural specification for Part 9.5:

β^TWFE=∑k≠UskUβ^kU2×2+∑k<ℓ(skℓkβ^kℓ2×2,k+skℓℓβ^kℓ2×2,ℓ),∑sab=1\hat{\beta}_{\text{TWFE}} = \sum_{k \neq U} s_{kU}\hat{\beta}_{kU}^{2\times 2} + \sum_{k \lt \ell} \left(s_{k\ell}^k \hat{\beta}_{k\ell}^{2\times 2, k} + s_{k\ell}^\ell \hat{\beta}_{k\ell}^{2\times 2, \ell}\right), \quad \sum s_{ab} = 1

Estimator objective and moment conditions:

τATT=E[Yit(1)−Yit(0)  |  Di=1],EN[ψ(Wi;τ^,η^)]=0\tau_{\text{ATT}} = \text{E}\left[Y_{it}(1) - Y_{it}(0) \;\middle|\; D_i = 1\right], \quad \text{E}_N\left[\psi\left(W_i; \hat{\tau}, \hat{\eta}\right)\right] = 0
Methodological Scope Boundary:When empirical data violate the identification conditions of Part 9.5, researchers should transition to the extended methodological parts in Chapter 9 or apply appropriate instrumental-variable and cluster-robust corrections.

9.5.2. Econometric Model Lessons in Part 9.5​

9.5.1 · bacon_decomposition
9.5.1. Goodman-Bacon Staggered TWFE Weight Decomposition

Decomposes the canonical staggered TWFE coefficient into exact 2x2 DID comparisons across Treated vs Untreated, Early vs Late, and forbidden...

Explore Guide
9.5.2 · sun_abraham_did
9.5.2. Sun-Abraham Interaction-Weighted Event-Study DID

Estimates saturated cohort-specific dynamic treatment effects relative to never-treated or last-treated controls and aggregates them by empi...

Explore Guide
9.5.3 · borusyak_imputation_did
9.5.3. Borusyak-Jaravel-Spiess Counterfactual Imputation DID

Fits unit, time, and covariate effects exclusively on untreated observations Omega_0 to impute counterfactual Y — 0 — and aggregate unbiased...

Explore Guide
9.5.4 · dechaisemartin_did
9.5.4. De Chaisemartin Dynamic Switching Treatment DID

Compares units switching treatment status against clean control units holding the same baseline treatment status unchanged, allowing policie...

Explore Guide
9.5.5 · wooldridge_etwfe
9.5.5. Wooldridge Extended Two-Way Mundlak Fixed-Effects DID

Restores full heterogeneity robustness to two-way fixed effects by saturating cohort-by-post-time cells alongside cohort-demeaned covariate ...

Explore Guide
9.5.6 · lp_did
9.5.6. Clean-Control Local Projections Difference-in-Differences

Combines horizon-by-horizon local projections with clean-control sample pruning so already-treated units never contaminate dynamic treatment...

Explore Guide
9.5.7 · honest_did_sensitivity
9.5.7. Rambachan-Roth HonestDiD Parallel-Trends Sensitivity

Constructs robust partial-identification confidence intervals when post-treatment trend violations are bounded by M_bar times the worst pre-...

Explore Guide
9.5.8 · synthetic_did
9.5.8. Synthetic Difference-in-Differences

Combines ridge-regularized simplex donor unit weights and pre-treatment time weights inside a two-way fixed-effects regression for doubly ro...

Explore Guide

9.5.3. Comparative Execution Syntax Across Stata 18, R 4.x, and Python 3.11+​

Section & Model TitleEstimator KeyStata 18 MP SyntaxR 4.x SyntaxPython 3.11+ SyntaxSupport
9.5.1 · Goodman-Bacon Staggered TWFE Weight Decompositionbacon_decompositionbacondecomp y treat, ddetailbacondecomp::bacon(y ~ treat, data = df, id_var = 'id', time_var = 'year')PanelOLS.from_formula('y ~ 1 + treat + EntityEffects + TimeEffects', data=pdata).fit()Available
9.5.2 · Sun-Abraham Interaction-Weighted Event-Study DIDsun_abraham_dideventstudyinteract y lead* lag*, cohort(first_treat) control_cohort(never) absorb(id year) vce(cluster id)fixest::feols(y ~ x1 + sunab(first_treat, year) | id + year, cluster = ~id, data = df)pyfixest.event_study(df, yname='y', idname='id', tname='year', gname='first_treat', estimator='saturated')Available
9.5.3 · Borusyak-Jaravel-Spiess Counterfactual Imputation DIDborusyak_imputation_diddid_imputation y id year first_treat, horizons(0/5) pretrends(4)did2s::did2s(df, yname = 'y', first_stage = ~ 0 | id + year, second_stage = ~ i(rel_time), treatment = 'treat', cluster_var = 'id')pyfixest.did2s(df, yname='y', first_stage='~ 0 | id + year', second_stage='~ treat', treatment='treat', cluster='id')Available
9.5.4 · De Chaisemartin Dynamic Switching Treatment DIDdechaisemartin_diddid_multiplegt_dyn y id year treat, effects(5) placebo(3) cluster(id)DIDmultiplegtDYN::did_multiplegt_dyn(df, 'y', 'id', 'year', 'treat', effects = 5, placebo = 3)PanelOLS.from_formula('dy ~ 1 + d_treat + x1 + TimeEffects', data=pdata).fit(cov_type='clustered', cluster_entity=True)Available
9.5.5 · Wooldridge Extended Two-Way Mundlak Fixed-Effects DIDwooldridge_etwfexthdidregress twfe (y x1) (treat), group(id)etwfe::etwfe(fml = y ~ x1, tvar = year, gvar = first_treat, data = df, vcov = ~id)pyfixest.feols('y ~ treat : i(cohort, year) + x1 | id + year', data=df, vcov={'CRV1': 'id'})Available
9.5.6 · Clean-Control Local Projections Difference-in-Differenceslp_didlpdid y, unit(id) time(year) treat(treat) pre_window(4) post_window(6)fixest::feols(dy_h ~ d_treat + x1 | year, subset = clean_sample, cluster = ~id, data = df)pyfixest.lpdid(df, yname='y', idname='id', tname='year', gname='first_treat')Available
9.5.7 · Rambachan-Roth HonestDiD Parallel-Trends Sensitivityhonest_did_sensitivityhonestdid, pre(1/4) post(5/8) mvec(0.5(0.5)2)HonestDiD::createSensitivityResults_relativeMagnitudes(betahat, sigma, numPrePeriods = 4, numPostPeriods = 4)scipy.optimize.linprog(c_obj, A_ub=A_rm, b_ub=b_rm)Available
9.5.8 · Synthetic Difference-in-Differencessynthetic_didsdid y id year treat, vce(placebo) reps(200)synthdid::synthdid_estimate(Y, N0, T0)SynthDID().fit(Y_panel, N0, T0)Available

| 9.5.9 · Targeted Maximum Likelihood Estimation van der Laan Rubin | tmle_targeted_mle | teffects aipw (y x1 x2) (treat x1 x2), vce(robust) | tmle::tmle | Clever-covariate targeting step + Efficient Influence Function SE | Available | | 9.5.10 · Potential Outcomes Causal Mediation ACME and ADE Imai Keele Yamamoto | causal_mediation_imai | mediate (y x1) (m x1) (treat) / sem + estat teffects | mediation::mediate(med.fit, out.fit, treat = 'treat', mediator = 'm') | Sequential ignorability mediator/outcome decomposition + ACME/ADE inference | Available | | 9.5.11 · Empirical Welfare Maximization and Optimal Policy Tree Kitagawa Tetenov Athey Wager | optimal_policy_tree_kitagawa | teffects ra (y x1 x2) (treat), vce(robust) | policytree::policy_tree + grf::double_robust_scores | Doubly-robust welfare scores + optimal threshold policy rule search | Available | | 9.5.12 · Heckman Vytlacil Local IV Marginal Treatment Effects | marginal_treatment_effects_mte | mtefe y (treat = z_iv) x1 / teffects ra (y x1) (treat) | ivmte::ivmte / mtefe::mtefe | Local Instrumental Variables polynomial propensity derivative MTE + ATE/ATT integration | Available | | 9.5.13 · Lee Sharp Nonparametric Sample Selection Treatment Effect Bounds | lee_trimming_bounds | leebounds y treat, cieffect / regress y treat x1, vce(robust) | leebounds::leebounds | Lee (2009) upper/lower quantile-trimmed sharp bounds + Imbens-Manski (2004) CI | Available | | 9.5.14 · DiNardo Fortin Lemieux Counterfactual Reweighting and Changes in Changes | changes_in_quantiles_dfl_dinardo | dfl treat x1, outcome(y) / teffects ipwra (y x1) (treat x1) | qte::CiC(y ~ treat, t = year, tmin1 = t0, t = t1, data = df) | DiNardo-Fortin-Lemieux propensity-odds reweighting + Athey-Imbens quantile counterfactuals | Available | | 9.5.15 · Athey Imbens Nuclear Norm Matrix Completion Causal Panel Estimator | matrix_completion_panel_athey | fect y, treat(treat) unit(entity) time(year) cov(x1) method(mc) | fect::fect(y ~ treat + x1, data = df, index = c('entity', 'year'), method = 'mc') | Athey et al. (2021) Singular-Value-Thresholding (SVT) nuclear-norm matrix completion + ATT | Available |

9.5.4. Standard Implementation Workflow for Part 9.5​

Step 1. Load Standardized Practice Datasets From VietLOD, EcoData, or Finco

Download the model-specific .csv practice dataset in Part 9.5 or extract custom empirical panels from EcoData and Finco.

Step 2. Select the Optimal Estimator for Your Error and Sample Structure

Compare the estimators from 9.5.1 to 9.5.15 in the syntax matrix above and execute the estimation in Stata 18 MP, R 4.x, or Python 3.11+.

Step 3. Run Mandatory Diagnostics and Export Publication Tables on EcoLab

Verify all required diagnostics including Tổng tỷ trọng và ước lượng DID trung bình theo 3 nhóm, tỷ phần trọng số bị ô nhiễm động học. and dispatch the specification to EcoLab for automated journal-grade reporting.