Commit 458632f
fix(did): close remaining review follow-ups — H3/H4/H6/H7
Finishes the polish round so the DID module can be declared release-ready.
H3. _etwfe_never_only no longer mutates the caller's DataFrame.
Removed the _ft_cache helper column; the cohort membership is now
computed into a local Series and consumed inline. Verified that
df.columns is unchanged after the call. Docstring also notes the
per-cohort cluster SE adjustment so users aren't surprised when
the aggregated SE differs from a full-sample fit.
H4. Slope indexing in _etwfe_with_xvar is now name-keyed.
Builds an explicit coef_index dict ({column_name: position}) at
design-matrix construction time; cohort ATT and per-xvar slopes
are extracted by dict lookup, never by arithmetic offset.
base_vcov likewise uses np.ix_ over the cohort-name keys. This
makes future column-order refactors safe. A regression test
verifies that reordering xvar=['x1','x2'] vs ['x2','x1'] yields
identical per-cohort slopes (and that slope_x1 != slope_x2 on
heterogeneous DGPs).
H6. Repeated-cross-section design warns on rank deficiency.
Before the OLS fit, _etwfe_repeated_cs computes the design-matrix
rank and, if deficient, emits a RuntimeWarning naming the deficit
and suggesting concrete remedies. The pinv fallback in _ols_fit
still runs so the regression doesn't crash, but the user now has
a chance to notice a silently pathological specification.
H7. etwfe_emfx gains include_leads for full event-study output.
wooldridge_did now builds event-time dummies for all rel_time
values except rel = -1 (the reference category), so pre-trend
leads are estimated alongside post-treatment lags. etwfe_emfx
gains an include_leads=False default (backward-compat); set
True to return the full event study including negative event
times. SE uses the same vcov-based delta method (H1 fix).
Tests: 4 new regression cases (tests/test_did_summary.py), total 27
passing in 1.85s (was 23).
Combined with the prior review fixes (C1-C5, H1/H2/H5), all 8 issues
flagged by the code-review agent are now closed. The remaining M/L
items are genuine polish (markdown cosmetics, dead-code pruning, API
ergonomics) that don't affect correctness.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent d7c48f1 commit 458632f
2 files changed
Lines changed: 144 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
186 | 189 | | |
187 | 190 | | |
188 | 191 | | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
192 | | - | |
193 | | - | |
194 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
195 | 199 | | |
196 | 200 | | |
197 | 201 | | |
| |||
308 | 312 | | |
309 | 313 | | |
310 | 314 | | |
311 | | - | |
312 | | - | |
313 | | - | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
314 | 324 | | |
315 | 325 | | |
316 | 326 | | |
| |||
564 | 574 | | |
565 | 575 | | |
566 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
567 | 584 | | |
568 | 585 | | |
569 | 586 | | |
| |||
597 | 614 | | |
598 | 615 | | |
599 | 616 | | |
600 | | - | |
| 617 | + | |
601 | 618 | | |
602 | 619 | | |
603 | | - | |
604 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
605 | 625 | | |
606 | 626 | | |
607 | 627 | | |
| |||
610 | 630 | | |
611 | 631 | | |
612 | 632 | | |
613 | | - | |
614 | | - | |
615 | | - | |
| 633 | + | |
| 634 | + | |
616 | 635 | | |
617 | 636 | | |
618 | 637 | | |
| |||
633 | 652 | | |
634 | 653 | | |
635 | 654 | | |
636 | | - | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
637 | 658 | | |
638 | 659 | | |
639 | 660 | | |
| |||
751 | 772 | | |
752 | 773 | | |
753 | 774 | | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
754 | 792 | | |
755 | 793 | | |
756 | 794 | | |
| |||
816 | 854 | | |
817 | 855 | | |
818 | 856 | | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
819 | 866 | | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
820 | 870 | | |
821 | | - | |
822 | | - | |
823 | | - | |
| 871 | + | |
| 872 | + | |
824 | 873 | | |
825 | 874 | | |
826 | | - | |
827 | | - | |
| 875 | + | |
828 | 876 | | |
829 | 877 | | |
830 | 878 | | |
| |||
834 | 882 | | |
835 | 883 | | |
836 | 884 | | |
837 | | - | |
838 | | - | |
| 885 | + | |
839 | 886 | | |
840 | 887 | | |
841 | 888 | | |
| |||
1404 | 1451 | | |
1405 | 1452 | | |
1406 | 1453 | | |
| 1454 | + | |
1407 | 1455 | | |
1408 | 1456 | | |
1409 | 1457 | | |
| |||
1429 | 1477 | | |
1430 | 1478 | | |
1431 | 1479 | | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
1432 | 1489 | | |
1433 | 1490 | | |
1434 | 1491 | | |
| |||
1554 | 1611 | | |
1555 | 1612 | | |
1556 | 1613 | | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1557 | 1620 | | |
1558 | 1621 | | |
1559 | 1622 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
0 commit comments