Skip to content

Commit a56e388

Browse files
igerberclaude
andcommitted
Polish: document vcov_type on DifferenceInDifferences and MultiPeriodDiD
Class-level docstrings now fully describe the vcov_type enum (classical, hc1, hc2, hc2_bm) on DifferenceInDifferences and MultiPeriodDiD, and clarify that robust is a legacy alias. Renamed test_set_params_rejects_conflict_on_robust_only to test_set_params_robust_only_rederives_vcov_type so the name matches the asserted behavior (robust-only mutation re-derives vcov_type from the alias rather than raising). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 946a5ca commit a56e388

2 files changed

Lines changed: 45 additions & 9 deletions

File tree

diff_diff/estimators.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,25 @@ class DifferenceInDifferences:
4848
R-style formula for the model (e.g., "outcome ~ treated * post").
4949
If provided, overrides column name parameters.
5050
robust : bool, default=True
51-
Whether to use heteroskedasticity-robust standard errors (HC1).
51+
Legacy alias for ``vcov_type``. ``robust=True`` maps to
52+
``vcov_type="hc1"``; ``robust=False`` maps to ``vcov_type="classical"``.
53+
Explicit ``vcov_type`` overrides ``robust`` unless the pair is
54+
contradictory (e.g. ``robust=False, vcov_type="hc2"`` raises).
5255
cluster : str, optional
53-
Column name for cluster-robust standard errors.
56+
Column name for cluster-robust standard errors. Combined with
57+
``vcov_type``: with ``"hc1"`` dispatches to CR1 (Liang-Zeger); with
58+
``"hc2_bm"`` dispatches to CR2 Bell-McCaffrey (Pustejovsky-Tipton 2018
59+
symmetric-sqrt + Satterthwaite DOF).
60+
vcov_type : {"classical", "hc1", "hc2", "hc2_bm"}, optional
61+
Variance-covariance family. Defaults to the ``robust`` alias.
62+
63+
- ``"classical"``: non-robust OLS SEs, ``sigma_hat^2 * (X'X)^{-1}``.
64+
- ``"hc1"``: heteroskedasticity-robust HC1 with ``n/(n-k)`` adjustment
65+
(library default). With ``cluster=``, uses CR1 (Liang-Zeger).
66+
- ``"hc2"``: leverage-corrected meat (one-way only). Errors with
67+
``cluster=``; use ``"hc2_bm"`` for clustered Bell-McCaffrey.
68+
- ``"hc2_bm"``: one-way HC2 + Imbens-Kolesar (2016) Satterthwaite DOF;
69+
with ``cluster=``, Pustejovsky-Tipton (2018) CR2 cluster-robust.
5470
alpha : float, default=0.05
5571
Significance level for confidence intervals.
5672
inference : str, default="analytical"
@@ -833,9 +849,25 @@ class MultiPeriodDiD(DifferenceInDifferences):
833849
Parameters
834850
----------
835851
robust : bool, default=True
836-
Whether to use heteroskedasticity-robust standard errors (HC1).
852+
Legacy alias for ``vcov_type``. ``robust=True`` maps to
853+
``vcov_type="hc1"``; ``robust=False`` maps to ``vcov_type="classical"``.
854+
Explicit ``vcov_type`` overrides ``robust`` unless the pair is
855+
contradictory (e.g. ``robust=False, vcov_type="hc2"`` raises).
837856
cluster : str, optional
838-
Column name for cluster-robust standard errors.
857+
Column name for cluster-robust standard errors. Combined with
858+
``vcov_type``: with ``"hc1"`` dispatches to CR1 (Liang-Zeger); with
859+
``"hc2_bm"`` dispatches to CR2 Bell-McCaffrey (Pustejovsky-Tipton 2018
860+
symmetric-sqrt + Satterthwaite DOF).
861+
vcov_type : {"classical", "hc1", "hc2", "hc2_bm"}, optional
862+
Variance-covariance family. Defaults to the ``robust`` alias.
863+
864+
- ``"classical"``: non-robust OLS SEs, ``sigma_hat^2 * (X'X)^{-1}``.
865+
- ``"hc1"``: heteroskedasticity-robust HC1 with ``n/(n-k)`` adjustment
866+
(library default). With ``cluster=``, uses CR1 (Liang-Zeger).
867+
- ``"hc2"``: leverage-corrected meat (one-way only). Errors with
868+
``cluster=``; use ``"hc2_bm"`` for clustered Bell-McCaffrey.
869+
- ``"hc2_bm"``: one-way HC2 + Imbens-Kolesar (2016) Satterthwaite DOF;
870+
with ``cluster=``, Pustejovsky-Tipton (2018) CR2 cluster-robust.
839871
alpha : float, default=0.05
840872
Significance level for confidence intervals.
841873

tests/test_estimators_vcov_type.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ def test_set_params_rejects_conflict_robust_false_hc2(self):
105105
with pytest.raises(ValueError, match="robust=False conflicts with vcov_type"):
106106
est.set_params(robust=False, vcov_type="hc2")
107107

108-
def test_set_params_rejects_conflict_on_robust_only(self):
109-
"""Setting robust=False on an estimator with vcov_type='hc2_bm' raises."""
108+
def test_set_params_robust_only_rederives_vcov_type(self):
109+
"""Setting robust= alone after init re-derives vcov_type from the alias.
110+
111+
When only ``robust`` is passed to ``set_params``, the new ``robust`` value
112+
overrides the previously-set ``vcov_type`` via the alias rule:
113+
``robust=False`` -> ``"classical"``. This keeps the pair internally
114+
consistent rather than leaving the estimator with ``robust=False,
115+
vcov_type="hc2_bm"`` (a state that ``__init__`` forbids).
116+
"""
110117
est = DifferenceInDifferences(vcov_type="hc2_bm")
111-
# The user is asking for non-robust SEs on an explicitly-HC2-BM estimator.
112-
# set_params re-derives vcov_type to "classical" since only `robust` changed;
113-
# this is a coherent override of the prior vcov_type, not a silent mismatch.
114118
est.set_params(robust=False)
115119
assert est.vcov_type == "classical"
116120

0 commit comments

Comments
 (0)