Skip to content

Commit bfed3e6

Browse files
igerberclaude
andcommitted
Address green review P3s: return type, design2 to_dataframe, docstrings
- Fix _compute_covariate_residualization return type annotation to include failed_baselines set (was 2-tuple, now 3-tuple) - Add to_dataframe("design2") level for Design-2 results - Update to_dataframe() docstring with all new levels - Update results dataclass docstring: replace Phase 3 placeholder text with actual field descriptions for covariate_residuals, linear_trends_effects, heterogeneity_effects, design2_effects Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cd73917 commit bfed3e6

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

diff_diff/chaisemartin_dhaultfoeuille.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ def _compute_covariate_residualization(
27642764
baselines: np.ndarray,
27652765
first_switch_idx: np.ndarray,
27662766
rank_deficient_action: str = "warn",
2767-
) -> Tuple[np.ndarray, Dict[str, Any]]:
2767+
) -> Tuple[np.ndarray, Dict[str, Any], set]:
27682768
"""Residualize outcomes by partialling out covariates per baseline treatment.
27692769
27702770
Implements ``DID^X`` from Web Appendix Section 1.2 of de Chaisemartin &

diff_diff/chaisemartin_dhaultfoeuille_results.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,19 @@ class ChaisemartinDHaultfoeuilleResults:
320320
sup_t_bands : dict, optional
321321
Phase 2 placeholder (sup-t simultaneous confidence bands).
322322
covariate_residuals : pd.DataFrame, optional
323-
Phase 3 placeholder (``DID^X`` residuals).
323+
``DID^X`` first-stage diagnostics: per-baseline ``theta_hat``,
324+
``n_obs``, and ``r_squared``. Populated when ``controls`` is set.
324325
linear_trends_effects : dict, optional
325-
Phase 3 placeholder (``DID^{fd}`` group-specific linear trends).
326+
Cumulated ``DID^{fd}`` level effects ``delta^{fd}_l``. Keyed by
327+
horizon. Populated when ``trends_linear=True``.
328+
heterogeneity_effects : dict, optional
329+
Per-horizon heterogeneity test results ``beta^{het}_l``.
330+
Populated when ``heterogeneity`` is set.
331+
design2_effects : dict, optional
332+
Design-2 switch-in/switch-out descriptive summary. Populated
333+
when ``design2=True``.
326334
honest_did_results : Any, optional
327-
Phase 3 placeholder (HonestDiD integration on placebos).
335+
Reserved for HonestDiD integration on placebos.
328336
survey_metadata : Any, optional
329337
Always ``None`` in Phase 1 — survey integration is deferred to a
330338
separate effort after all phases ship.
@@ -863,6 +871,14 @@ def to_dataframe(self, level: str = "overall") -> pd.DataFrame:
863871
- ``"twfe_weights"``: per-(group, time) TWFE decomposition
864872
weights table. Only available when ``twfe_diagnostic=True``
865873
was passed to ``fit()``.
874+
- ``"heterogeneity"``: one row per horizon for the
875+
heterogeneity test ``beta^{het}_l``. Available when
876+
``heterogeneity`` is passed to ``fit()``.
877+
- ``"linear_trends"``: one row per horizon for the
878+
cumulated trend-adjusted level effects ``delta^{fd}_l``.
879+
Available when ``trends_linear=True``.
880+
- ``"design2"``: Design-2 switch-in/switch-out descriptive
881+
summary. Available when ``design2=True``.
866882
867883
Returns
868884
-------
@@ -1073,11 +1089,19 @@ def to_dataframe(self, level: str = "overall") -> pd.DataFrame:
10731089
rows.append({"horizon": h, **data})
10741090
return pd.DataFrame(rows)
10751091

1092+
elif level == "design2":
1093+
if self.design2_effects is None:
1094+
raise ValueError(
1095+
"Design-2 effects not available. Pass "
1096+
"design2=True with drop_larger_lower=False to fit()."
1097+
)
1098+
return pd.DataFrame([self.design2_effects])
1099+
10761100
else:
10771101
raise ValueError(
10781102
f"Unknown level: {level!r}. Use 'overall', 'joiners_leavers', "
10791103
f"'per_period', 'event_study', 'normalized', 'twfe_weights', "
1080-
f"'heterogeneity', or 'linear_trends'."
1104+
f"'heterogeneity', 'linear_trends', or 'design2'."
10811105
)
10821106

10831107

0 commit comments

Comments
 (0)