Difference-in-Differences causal inference in Python. Callaway-Sant'Anna, Synthetic DiD, Honest DiD, event studies. sklearn-like API, validated against R.
Repo igerber/diff-diff, read from GitHub 12 min ago. igerber has not joined Take My Repo.
LWDiDResults.pvalue and LWDiDResults.ci are removed (ledger rows M-151, M-152): the
3.10-born alias properties for p_value / conf_int were first shimmed with a FutureWarning
and then removed outright at 4.0 (item 9b of the cut). Read .p_value / .conf_int.
LWDiDResults.to_dataframe() is reshaped onto the shared results schema (ledger row
M-153): each level returns aggregate(level).to_dataframe() - columns level, label, target, att, se, t_stat, p_value, conf_int_lower, conf_int_upper, n, weight, df (the
event-study schema for level="event_study") - plus LWDiD's rolling, estimation_method
and vcov_type columns. The default "simple" is ONE headline row; the former per-cohort
rows are level="group" (without the old trailing "Overall" row). The term / cohort
column is now label, n_treated is the schema's n, n_obs and n_control are no longer
in the frame (both stay in to_dict()), and ci_lower / ci_upper are
conf_int_lower / conf_int_upper. to_csv() follows and takes the same level.
BusinessReport.to_dict() schema 2.0 -> 3.0: the StackedDiD assumption block no longer
carries the legacy clean_control key (read control_group). DiagnosticReport's schema stays
2.0 at this step. (Intermediate: later bullets in this release move the final 4.0 versions to
BUSINESS_REPORT_SCHEMA_VERSION 4.0 and DIAGNOSTIC_REPORT_SCHEMA_VERSION 3.0.)
Passing aggregate= or balance_e= to CallawaySantAnna.fit, EfficientDiD.fit,
StackedDiD.fit, ChaisemartinDHaultfoeuille.fit or HeterogeneousAdoptionDiD.fit (or
aggregate= to did_had_pretest_workflow) now raises Python's native
TypeError: ... unexpected keyword argument. TripleDifference's staggered-mode
aggregate=/balance_e= are untouched at this step (M-140/M-141; they are REMOVED later in
this release by the DDD container unification bullet below).
Positional slots after the removed parameters shift left. CallawaySantAnna:
survey_design 9 -> 7; EfficientDiD: survey_design 9 -> 7, store_eif 10 -> 8;
StackedDiD (aggregate sat before them): population, survey_design, covariates
7/8/9 -> 6/7/8; ChaisemartinDHaultfoeuille: L_max, covariates, trends_linear,
trends_nonparam, honest_did, heterogeneity, design2, survey_design each move one
slot left (7..14 -> 6..13). HeterogeneousAdoptionDiD.fit shifts nothing (everything after
the removed slot is keyword-only; a seventh positional now raises). Pass these by keyword.
CallawaySantAnnaResults.to_dataframe(level="event_study"|"group") and the
EfficientDiDResults twins raise on every fresh fit (the legacy fields are always None);
use results.aggregate(...).to_dataframe(). (Intermediate: the M-093 schema bullet below
supersedes this - since item 8b to_dataframe(level="event_study") recomputes the surface on
these classes instead of raising; level="group" still raises with the post-fit pointer.)
Passing aggregate= or balance_e= to ImputationDiD.fit, TwoStageDiD.fit or
ContinuousDiD.fit now raises Python's native TypeError: ... unexpected keyword argument.
Positional slots after the removed parameters shift left. ImputationDiD and
TwoStageDiD: survey_design 9 -> 7; ContinuousDiD: survey_design, covariates
8/9 -> 7/8. Pass these by keyword.
aggregate('event_study', balance_e=k) on a BOOTSTRAPPED ImputationDiD / TwoStageDiD
fit raises NotImplementedError (the relayed surface was computed unrestricted; re-fit with
n_bootstrap=0 for a balanced window). Analytic fits recompute with balance_e as before.
A bootstrapped ImputationDiD / TwoStageDiD / ContinuousDiD fit WITH bootstrap inference
but WITHOUT a stored surface - a 3.9-3.13 bootstrapped plain-fit pickle, or a fit whose
fail-soft materialization dropped it - raises ValueError from aggregate('event_study') /
aggregate('group') (previously NotImplementedError from the bootstrap gate); the message
names the refit. A 3.9-3.13 bootstrapped pickle fitted with balance_e=k stores a restricted
surface and the relay returns it as stored.
TripleDifference.fit(time=) in the 2x2x2 design now raises ValueError naming post=
(M-085). Through 3.x time= was the deprecated alias for the 0/1 post indicator and emitted
a FutureWarning (M-031); since 4.0 time means the staggered calendar column only.
Supplying both post= and time= keeps raising the "pass only post=" error.
Keyword mapping for callers of the removed class: eligibility= is partition= on
TripleDifference; the staggered fit parameters are keyword-only; cluster= raises in
staggered mode (use n_bootstrap > 0 for unit-level clustered inference). Users of
balance[did] stay on 3.x through that extra's diff-diff<4 pin, where the old name still
resolves.
TwoWayFixedEffects.fit(time=) in static mode now raises ValueError naming post=
(M-083). Through 3.x time= was the deprecated alias for the 0/1 post indicator and
emitted a FutureWarning (M-082); since 4.0 time means the event-study calendar column
only. Supplying both post= and time= keeps raising the "pass only post=" error.
EventStudyResults.period_effects is removed (M-016; the compatibility view
this item first shipped was retired at 4.0 by item 9b - no release carried it). Through
the pre-release window, on a calendar surface it returned the former calendar-keyed dict of
per-period records (period, effect, se, t_stat, p_value, conf_int, is_significant, significance_stars, reference period omitted; is_significant is evaluated at the fit's
alpha, where the removed record hard-coded 0.05; duplicate labels raise). Relative-time
aggregate("event_study") surfaces do not carry it (AttributeError, no warning). The
successor is to_dataframe() and the columnar arrays.
The 3.x "default reference_period has changed" FutureWarning is no longer emitted
(M-007): the event-study mode defaults to the last pre-period silently.
simulate_power and friends read the flat att/se/p_value/conf_int names from
unregistered custom estimators' results and raise TypeError naming _EstimatorProfile
otherwise (the avg_* fallback left with the removed container; pass result_extractor=
for other shapes).
4.0 cut, storage flip of the headline quintet (M-050..M-058). CallawaySantAnnaResults (and DMLDiDResults), SunAbrahamResults, ImputationDiDResults, TwoStageDiDResults, StackedDiDResults, EfficientDiDResults, WooldridgeDiDResults, ChaisemartinDHaultfoeuilleResults and ContinuousDiDResults now store the canonical att / se / t_stat / p_value / conf_int as their native dataclass fields (renamed in slot, so the positional constructor layout is unchanged) and take those names as constructor keywords (overall_att= raises TypeError). The 3.x overall_att / overall_se / overall_t_stat / overall_p_value / overall_conf_int names - and on ContinuousDiDResults all nine legacy spellings, the overall_att_* fields and the former silent overall_se-style aliases - are removed at 4.0 (item 9b retired the FutureWarning property shims this item first shipped - reading one raises AttributeError); they are absent from dataclasses.fields(), asdict() and to_dict(). 3.x pickles load unchanged (each container's __setstate__ rewrites the legacy keys on load). The bootstrap draw containers (bootstrap_results.overall_att_se and siblings) are unchanged; StaggeredTripleDiffResults kept its overall_* storage at this step and is removed by the DDD container unification bullet below.
Report schemas. DiagnosticReport.to_dict() reports headline_metric.name and target_parameter.headline_attribute as "att" for the nine containers above ("overall_att" under 3.x); DIAGNOSTIC_REPORT_SCHEMA_VERSION 2.0 -> 3.0. BusinessReport.to_dict() reports target_parameter.headline_attribute likewise; BUSINESS_REPORT_SCHEMA_VERSION 3.0 -> 4.0 (its headline block carries no name key). StaggeredTripleDiffResults kept headline_attribute: "overall_att" at this step (removed by the DDD unification below).
4.0 cut, DDD container unification (M-014, M-140, M-141). TripleDifference.fit() returns ONE TripleDifferenceResults for both designs: results.design is "2x2x2" or "staggered", the canonical att / se / t_stat / p_value / conf_int are native in both, the 2x2x2 positional layout is unchanged, and the staggered structure (group_time_effects, groups, time_periods, unit counts, control_group, base_period, anticipation, bootstrap_results, ...) is appended with defaults (group_time_effects is {} in the 2x2x2 design). The 3.x StaggeredTripleDiffResults class, its module, its overall_* fields and to_dict() keys, and its fit-time overall_att_es / overall_se_es / overall_t_stat_es / overall_p_value_es / overall_conf_int_es fields are REMOVED (3.x staggered pickles cannot load; 3.x 2x2x2 pickles load unchanged). The fit-time aggregate= / balance_e= keywords of TripleDifference.fit() are REMOVED (TypeError): aggregation is post-fit - results.aggregate('event_study') (EventStudyResults, balance_e=), results.aggregate('group') (AggregationResult) and results.aggregate('simple') (a one-row relay of the stored headline, both designs); bootstrapped fits REPLAY the fit-time multiplier bootstrap so sup-t bands and percentile inference match a 3.x fit-time aggregation; the 2x2x2 design fails the staggered levels closed. The paper's Eq. 4.14 overall is results.aggregate('simple', weights='event_time') (accepts balance_e=; both 3.x warnings preserved). summary() no longer prints the event-study / cohort / Eq. 4.14 blocks; to_dataframe('event_study' | 'group') raise with the post-fit pointer; to_dataframe(level=None) defaults to 'group_time' in the staggered design and 'overall' in 2x2x2 (whose one-row frame gains design, pscore_trim, alpha, df_inference). New field df_inference records the 2x2x2 engine's t df. plot_group_effects and its siblings raise ValueError on a 2x2x2 fit (no cells).
Report schemas. For staggered DDD fits DiagnosticReport.to_dict()['estimator'] and BusinessReport.to_dict()['estimator']['class_name'] read TripleDifferenceResults, and target_parameter.headline_attribute reads "att" (the last "overall_att"). Both schemas gain an additive key - DR a top-level design, BR estimator.design - "2x2x2" / "staggered" for TripleDifferenceResults, None otherwise. No version bump: DIAGNOSTIC_REPORT_SCHEMA_VERSION 3.0 and BUSINESS_REPORT_SCHEMA_VERSION 4.0 had not shipped (folded into the PR 5b bump). power.py's staggered-boundary guard no longer keys on aggregate / balance_e (an estimator_kwargs carrying them surfaces as fit()'s TypeError).
4.0 cut, df_convention default flip (M-004, M-005, M-006, M-128, M-129, M-130, M-131). The analytical tail-df convention for CLUSTERED fits defaults to "cluster" (the Stata/fixest t(G - 1) reference) instead of "residual" (the fitted residual df t(n - K_full)) on DifferenceInDifferences, TwoWayFixedEffects, LinearRegression, SunAbraham, WooldridgeDiD (OLS arms), StackedDiD and ImputationDiD (pretrends leads); LPDiD already defaulted to "cluster" at 3.9. What moves: p-values and confidence intervals on clustered analytical fits - TwoWayFixedEffects (static, and event-study with unit=), SunAbraham, WooldridgeDiD OLS and StackedDiD cluster at unit by default, so their default fits move; ImputationDiD moves on the pretrends=True lead rows; DifferenceInDifferences / LinearRegression move only with an explicit cluster= / cluster_ids=; the analytical lanes inside bootstrapped fits (WooldridgeDiD per-cell inference and post-fit aggregate(), ImputationDiD bootstrapped leads) move too, as do the fake-timing / fake-group placebo diagnostics and the power simulators that relay those p-values. What does not: point estimates, standard errors and t-statistics; survey-design fits (survey df keeps precedence); vcov_type="hc2_bm" (Bell-McCaffrey DOF keep precedence); bootstrap percentile p-values / CIs; unclustered and Conley fits; the BJS overall/post inference of ImputationDiD; WooldridgeDiD logit/poisson arms; permutation and leave-one-out diagnostics. df_convention="residual" restores the 3.x inference bit-for-bit; on the surfaces where the knob is a documented no-op (non-pretrends ImputationDiD, WooldridgeDiD logit/poisson) the inert-config UserWarning now fires for an explicit "residual" rather than for an explicit "cluster". SyntheticDiD inherits the flipped attribute from DifferenceInDifferences without reading it (no behaviour change).
SpilloverDiD auto-clusters at unit when cluster= is omitted ([M-080], item 7b of the 4.0 cut), mirroring TwoWayFixedEffects' carve-outs (explicit cluster= wins; the auto-cluster is dropped on the Conley path and never injected as a survey PSU). Its default standard errors, p-values and CIs move; cluster=False reproduces the 3.x observation-level HC1 numbers. Results report cluster_name="unit" / n_clusters. Inference stayed on the residual df at this step; the df_convention knob (next bullet, [M-154]) moves it to t(G - 1) in the same release.
cluster=False is the uniform explicit off-switch ([M-080]): the plain heteroskedasticity-robust sandwich with residual-df t inference on TwoWayFixedEffects (static + event-study; one-way CR2 Bell-McCaffrey under hc2_bm), SunAbraham, WooldridgeDiD (OLS within-transform lane with the absorbed-FE full-K rescale; logit/poisson plain QMLE sandwich) and LPDiD (per-horizon HC1; if_robust unclustered IF variance on the regression-adjustment path; implicit per-observation PSUs under a survey design); an accepted bit-identical no-op on the unit-level-by-construction estimators (CallawaySantAnna incl. its RC auto-PSU path, EfficientDiD incl. hausman_pretest, DMLDiD, ChaisemartinDHaultfoeuille, staggered TripleDifference, LWDiD incl. the sensitivity helpers, HeterogeneousAdoptionDiD, ImputationDiD, TwoStageDiD) and on the 2x2 DifferenceInDifferences / 2x2x2 TripleDifference surfaces; still rejected on StackedDiD. Rejected with inference="wild_bootstrap" (DiD/TWFE), WooldridgeDiD(n_bootstrap > 0) and vcov_type="hc2_bm" on SunAbraham/WooldridgeDiD (cluster-only Bell-McCaffrey DOF; tracked in TODO.md).
cluster accepts str | None | False only ([M-155], diff_diff.utils.validate_cluster): True and non-str column labels raise one shared ValueError at construction, through set_params and at fit() on every estimator exposing the parameter (DMLDiD's existing rule generalized; integer-labelled cluster columns must be renamed).
Cluster metadata: DifferenceInDifferences / TwoWayFixedEffects report n_clusters from the regression's effective cluster count on non-survey analytical fits (previously None unless the wild bootstrap ran); SunAbrahamResults gains an appended n_clusters field and reports cluster_name on clustered analytical fits (previously None off the Conley path), and its summary() renders the variance-family label on analytical non-survey fits; TwoWayFixedEffects under a survey design with no explicit cluster= reports cluster_name=None (the auto-cluster is never injected as a PSU).
SpilloverDiD gains the three-value df_convention knob with the 4.0 default "cluster" ([M-154], item 7c of the 4.0 cut): p-values and confidence intervals on its clustered lanes - the unit auto-cluster and an explicit cluster= - now use the Stata/fixest t(G - 1) reference like every other auto-clustered default, with G the effective cluster count reported as n_clusters. Point estimates, standard errors and t-statistics never move. df_convention="residual" restores the 3.x residual-df inference bit-for-bit; "normal" is deliberate z. "cluster" falls back to the residual df on cluster=False and on every vcov_type="conley" fit, an explicit product-kernel cluster= included ("normal" still selects z there); a survey_design df keeps precedence under every value; a saturated stage-2 sample stays all-NaN under every value. SpilloverDiDResults reports df_convention and inference_df (also in to_dict()).
Event-study reference rows are marked explicitly ([M-093], item 8a of the 4.0 cut): every native event_study_effects dict that materializes its normalization row (StackedDiD, ImputationDiD, TwoStageDiD, SpilloverDiD, the CallawaySantAnna/DMLDiD universal-base aggregation carrier) now carries "is_reference": True on that row and NO count key there - the 3.x n_obs == 0 / n_groups == 0 sentinel is retired, and every remaining zero count is a genuine count (a non-estimable horizon). SpilloverDiD's event-study att_dynamic / spillover_effects frames gain a boolean is_reference column with n_obs = NaN on the reference rows (the column is float; to_dict() records follow). The native to_dataframe(level="event_study") frames of StackedDiD / bootstrapped ImputationDiD / TwoStageDiD rendered the reference row's n_obs as NaN (float column) at this step; the 8b schema rewire (next bullet) replaces those frames. plot_event_study, plot_honest_event_study, HonestDiD, PreTrendsPower and DiagnosticReport locate the reference by the key on their raw-dict routes - dispatch, admission, rendering and exception types are unchanged. TwoStageDiD.summary() now prints its genuine all-filtered horizons as NaN rows instead of a mislabeled [ref: h] line. 3.x pickles are migrated on load. SunAbraham (omitted row, reference_period) and EfficientDiD (PT-Post anchor, an estimated cell named by reference_period) are unchanged.
Every results class's to_dataframe(level="event_study") now emits the unified EVENT_STUDY_SCHEMA ([M-093], item 8b of the 4.0 cut): event_time, att, se, t_stat, p_value, conf_int_lower, conf_int_upper, cband_lower, cband_upper, n, df, is_reference, estimand - the frame results.aggregate("event_study").to_dataframe() returns (CallawaySantAnna/DMLDiD, EfficientDiD, ImputationDiD, TwoStageDiD, StackedDiD, ContinuousDiD, TripleDifference staggered, ChaisemartinDHaultfoeuille, HAD event-study results, DurationDiD, LWDiD) or the builder frame (SunAbraham, LPDiD, WooldridgeDiD, SpilloverDiD). The 3.x bespoke frames are gone: relative_period -> event_time; effect / att_glob / LPDiD's coefficient -> att; conf_int_lo/hi, conf_low/high, HAD's conf_int_low/high -> conf_int_lower/conf_int_upper; n_obs -> n (NaN on the is_reference row); dCDH's horizon -> event_time on the paper's l1_first_switch convention, its per-horizon estimand labels (DID^pl_l / ref / DID_l) are not carried (estimand is "att") and its reference row is marked is_reference instead of n_obs 0. WooldridgeDiD and LWDiD append their fit-configuration columns after the schema (cohort_trends, aggregation_weights; rolling, estimation_method, vcov_type), and WooldridgeDiD.to_dataframe(level="event_study") (its default level) now RAISES before aggregate("event_study", weights=) instead of returning an empty frame. CallawaySantAnna, EfficientDiD, TripleDifference and analytical ImputationDiD / TwoStageDiD / ContinuousDiD no longer raise "not stored on 4.0 fits" - the level recomputes the surface from the retained kit (bootstrapped CallawaySantAnna / EfficientDiD / TripleDifference fits replay the fit-time bootstrap on every call; an ImputationDiD replicate-weight survey fit with pretrends=True raises NotImplementedError as aggregate() does); a kit-less pre-3.9 pickle, or a bootstrapped pickle predating the replay state, that still carries a stored dict now raises where it returned a frame. level="group" on those three classes still raises with the post-fit pointer. New levels: SpilloverDiDResults.to_dataframe(level="simple" | "event_study") (default "simple", the former one-row frame; aggregate-mode fits raise on "event_study"), HeterogeneousAdoptionDiDEventStudyResults.to_dataframe(level="event_study"), DurationDiDResults.to_dataframe(level="event_study"). An LPDiD fit whose stored event-study frame is empty raises instead of returning the empty frame.
4.0 cut, item 9b: the compatibility shims scheduled for a 5.0 removal are removed at 4.0 (maintainer
decision - no 4.x debt; none of these FutureWarning shims ever reached a release, so the released
3.x names break without a warned release - docs/migration-4.0.md is the notice). The 3.x
overall_att / overall_se / overall_t_stat / overall_p_value / overall_conf_int names on
CallawaySantAnnaResults (and DMLDiDResults), SunAbrahamResults, ImputationDiDResults,
TwoStageDiDResults, StackedDiDResults, EfficientDiDResults, WooldridgeDiDResults,
ChaisemartinDHaultfoeuilleResults and - all nine spellings, overall_att_* included -
ContinuousDiDResults raise AttributeError; read the canonical att / se / t_stat /
p_value / conf_int (M-050..M-058). 3.x pickles still load (the __setstate__ key migration
stays). EventStudyResults.period_effects is gone; read to_dataframe() or the columnar arrays
(M-016). LWDiDResults.pvalue / .ci are gone; read .p_value / .conf_int (M-151, M-152).
SyntheticControl(inner_max_iter=, inner_min_decrease=) are removed (M-148, M-149; the
DeprecationWarning shipped in 3.13.0): passing either is a TypeError, and the positional
parameters after them (standardize, alpha, seed, v_cv_t0) move two slots left - pass
them by keyword.
run_placebo_test / run_all_placebo_tests: time is the calendar column only and
post_periods is required for every test_type (M-156, M-157; spec section 8 rule 1). The
0/1 post dummy the permutation and leave-one-out tests need is derived as
data[time].isin(post_periods); a missing time column, missing/empty post_periods, missing
values in time, post_periods values absent from the column, or a pre-existing _placebo_post
column raise ValueError (on the suite wrapper before any test runs). Calls that passed the 0/1
indicator as time= with post_periods=[1] return identical numbers; calls that omitted
post_periods
Full Changelog: v3.12.0...v3.13.0
Full Changelog: v3.11.1...v3.12.0
Full Changelog: v3.11.0...v3.11.1
Full Changelog: v3.10.0...v3.11.0
Full Changelog: v3.9.1...v3.10.0