|
1 | 1 | # EventStudyInteracts.py |
2 | 2 |
|
3 | | -Python project scaffold for a `pyfixest`-backed implementation of the |
4 | | -Sun and Abraham interaction-weighted event-study estimator. |
5 | | - |
6 | | -This repository is currently in the planning/scaffold stage. The intended |
7 | | -package import name is `eventstudyinteracts`, and the primary public function |
8 | | -will be `eventreg(...)`, mirroring the workflow of |
9 | | -[`EventStudyInteracts.jl`](https://github.com/xiaobaaaa/EventStudyInteracts.jl) |
10 | | -while preserving the native features of |
| 3 | +`EventStudyInteracts.py` is a Python implementation of the Sun and Abraham |
| 4 | +interaction-weighted event-study estimator, built as a thin layer over |
11 | 5 | [`pyfixest`](https://github.com/py-econometrics/pyfixest). |
12 | 6 |
|
13 | | -## Design Goal |
| 7 | +The estimator keeps `pyfixest.feols()` as the regression engine. First-stage |
| 8 | +coefficients and covariance matrices come from pyfixest, including its fast |
| 9 | +fixed-effect demeaning backends and solver choices. The second-stage cohort-share |
| 10 | +regressions are also fit with pyfixest; the package only adds the |
| 11 | +interaction-weighted aggregation and the cross-equation delta-method covariance |
| 12 | +that pyfixest does not expose directly. |
14 | 13 |
|
15 | | -The package should feel like a thin, Python-native layer over `pyfixest`, not a |
16 | | -separate regression engine. In particular, the implementation plan keeps |
17 | | -`pyfixest.feols()` as the estimation backend and forwards important backend |
18 | | -options such as: |
| 14 | +## Installation |
19 | 15 |
|
20 | | -- `vcov`, `vcov_kwargs`, `ssc`, and cluster-robust inference settings |
21 | | -- `weights` and `weights_type` |
22 | | -- `fixef_rm`, `fixef_tol`, `fixef_maxiter`, and `collin_tol` |
| 16 | +```bash |
| 17 | +python -m pip install -e ".[dev]" |
| 18 | +``` |
| 19 | + |
| 20 | +The package requires Python 3.10+ and `pyfixest>=0.50.1`. |
| 21 | + |
| 22 | +## Basic Usage |
| 23 | + |
| 24 | +```python |
| 25 | +from eventstudyinteracts import eventreg |
| 26 | + |
| 27 | +fit = eventreg( |
| 28 | + "ln_wage ~ age + tenure | idcode + year", |
| 29 | + data=df, |
| 30 | + rel_varlist=["g_4", "g_3", "g_2", "g0", "g1", "g2", "g3"], |
| 31 | + cohort="first_treat", |
| 32 | + control_cohort="never_treat", |
| 33 | + vcov={"CRV1": "idcode"}, |
| 34 | + demeaner_backend="rust-cg", |
| 35 | +) |
| 36 | + |
| 37 | +fit.coef() |
| 38 | +fit.se() |
| 39 | +fit.vcov() |
| 40 | +fit.tidy() |
| 41 | +``` |
| 42 | + |
| 43 | +`control_cohort` is a boolean column identifying never-treated/control rows. |
| 44 | +`rel_varlist` should contain the relative-time indicator columns to aggregate, |
| 45 | +in the output order you want. |
| 46 | + |
| 47 | +## pyfixest Passthrough |
| 48 | + |
| 49 | +`eventreg(...)` mirrors pyfixest naming where possible and forwards the important |
| 50 | +performance and inference options: |
| 51 | + |
| 52 | +- `vcov`, `vcov_kwargs`, `ssc` |
| 53 | +- `weights`, `weights_type` |
| 54 | +- `fixef_rm`, `fixef_tol`, `fixef_maxiter`, `collin_tol` |
23 | 55 | - `solver` |
24 | | -- `demeaner_backend` with `numba`, `rust`, `jax`, `cupy`, `cupy32`, `cupy64`, |
25 | | - and `scipy` |
26 | | -- `copy_data`, `store_data`, `lean`, and `use_compression` |
| 56 | +- `demeaner_backend`, including `numba`, `rust`, `rust-cg`, `jax`, `cupy`, |
| 57 | + `cupy32`, `cupy64`, and `scipy` |
| 58 | +- `copy_data`, `store_data`, `lean`, `use_compression` |
27 | 59 | - `split` and `fsplit` |
28 | 60 |
|
29 | | -## Current Layout |
| 61 | +The IW share covariance currently supports the EventStudyInteracts.jl parity |
| 62 | +modes: `iid`/`simple`, `hetero`/`HC1`, and one- or two-way `{"CRV1": ...}`. |
30 | 63 |
|
31 | | -- `src/eventstudyinteracts/`: future package source |
| 64 | +## Project Layout |
| 65 | + |
| 66 | +- `src/eventstudyinteracts/`: package source |
| 67 | +- `tests/`: unit and estimator regression tests |
| 68 | +- `scripts/check_external_parity.py`: optional local parity harness for Python, |
| 69 | + R fixest, Stata `eventstudyinteract`, and Julia `EventStudyInteracts.jl` |
32 | 70 | - `docs/requirements.md`: detailed requirements |
33 | | -- `docs/design/api.md`: proposed Python API and result object design |
34 | | -- `docs/design/upstream-analysis.md`: notes from `EventStudyInteracts.jl` and |
35 | | - `pyfixest` |
| 71 | +- `docs/design/api.md`: API and result object design |
| 72 | +- `docs/design/upstream-analysis.md`: upstream implementation notes |
36 | 73 | - `docs/implementation-plan.md`: milestone plan |
37 | | -- `docs/workflows/`: development, maintenance, GitHub, and release workflows |
38 | | -- `tests/`: test suite placeholder |
39 | | -- `references/`: external parity baselines |
40 | | -- `benchmarks/`: performance scripts and outputs |
41 | | -- `.github/workflows/ci.yml`: initial CI skeleton |
| 74 | +- `.github/workflows/ci.yml`: lint, format, test, and compile checks |
| 75 | + |
| 76 | +## Verification |
| 77 | + |
| 78 | +Current local checks: |
42 | 79 |
|
43 | | -## Status |
| 80 | +```bash |
| 81 | +python -m ruff check src tests scripts |
| 82 | +python -m ruff format --check src tests scripts |
| 83 | +python -m pytest |
| 84 | +python -m compileall src tests |
| 85 | +python scripts/check_external_parity.py |
| 86 | +``` |
44 | 87 |
|
45 | | -No estimator implementation is claimed yet. The next implementation step is to |
46 | | -add `eventreg(...)` with tests that first lock the single-cohort equivalence |
47 | | -case before implementing the full multi-cohort IW covariance. |
| 88 | +The external parity script compares coefficients against R `fixest`, Stata |
| 89 | +`eventstudyinteract`, and Julia `EventStudyInteracts.jl` when those tools are |
| 90 | +available. It also compares a single-cohort IW covariance matrix against Stata; |
| 91 | +Julia/R saturated paths use different small-sample conventions in that fixture |
| 92 | +and are reported explicitly as skipped for vcov. |
0 commit comments