StataFlow 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. stataflow-0.1.0/LICENSE +21 -0
  2. stataflow-0.1.0/PKG-INFO +203 -0
  3. stataflow-0.1.0/README.md +173 -0
  4. stataflow-0.1.0/pyproject.toml +47 -0
  5. stataflow-0.1.0/setup.cfg +4 -0
  6. stataflow-0.1.0/src/StataFlow.egg-info/PKG-INFO +203 -0
  7. stataflow-0.1.0/src/StataFlow.egg-info/SOURCES.txt +47 -0
  8. stataflow-0.1.0/src/StataFlow.egg-info/dependency_links.txt +1 -0
  9. stataflow-0.1.0/src/StataFlow.egg-info/requires.txt +8 -0
  10. stataflow-0.1.0/src/StataFlow.egg-info/top_level.txt +1 -0
  11. stataflow-0.1.0/src/statapy/__init__.py +74 -0
  12. stataflow-0.1.0/src/statapy/compat/__init__.py +1 -0
  13. stataflow-0.1.0/src/statapy/compat/stata/__init__.py +25 -0
  14. stataflow-0.1.0/src/statapy/compat/stata/did.py +142 -0
  15. stataflow-0.1.0/src/statapy/compat/stata/factor_variables.py +348 -0
  16. stataflow-0.1.0/src/statapy/compat/stata/glm.py +108 -0
  17. stataflow-0.1.0/src/statapy/compat/stata/hdfe.py +97 -0
  18. stataflow-0.1.0/src/statapy/compat/stata/iv.py +96 -0
  19. stataflow-0.1.0/src/statapy/compat/stata/linear.py +115 -0
  20. stataflow-0.1.0/src/statapy/compat/stata/rdrobust.py +114 -0
  21. stataflow-0.1.0/src/statapy/estimators/__init__.py +14 -0
  22. stataflow-0.1.0/src/statapy/estimators/absorbing_ols.py +628 -0
  23. stataflow-0.1.0/src/statapy/estimators/csdid.py +376 -0
  24. stataflow-0.1.0/src/statapy/estimators/did_imputation.py +392 -0
  25. stataflow-0.1.0/src/statapy/estimators/eventstudyinteract.py +318 -0
  26. stataflow-0.1.0/src/statapy/estimators/fe.py +503 -0
  27. stataflow-0.1.0/src/statapy/estimators/glm.py +656 -0
  28. stataflow-0.1.0/src/statapy/estimators/iv.py +983 -0
  29. stataflow-0.1.0/src/statapy/estimators/ols.py +603 -0
  30. stataflow-0.1.0/src/statapy/estimators/ppmlhdfe.py +518 -0
  31. stataflow-0.1.0/src/statapy/estimators/rdrobust.py +853 -0
  32. stataflow-0.1.0/src/statapy/postestimation.py +169 -0
  33. stataflow-0.1.0/src/statapy/results/__init__.py +5 -0
  34. stataflow-0.1.0/src/statapy/results/result.py +211 -0
  35. stataflow-0.1.0/src/statapy/stata_runner/__init__.py +5 -0
  36. stataflow-0.1.0/src/statapy/stata_runner/runner.py +234 -0
  37. stataflow-0.1.0/tests/test_compat_stata_did.py +253 -0
  38. stataflow-0.1.0/tests/test_compat_stata_glm.py +118 -0
  39. stataflow-0.1.0/tests/test_compat_stata_hdfe.py +84 -0
  40. stataflow-0.1.0/tests/test_compat_stata_iv.py +92 -0
  41. stataflow-0.1.0/tests/test_compat_stata_linear.py +95 -0
  42. stataflow-0.1.0/tests/test_factor_variables.py +461 -0
  43. stataflow-0.1.0/tests/test_hdfe_synthetic.py +420 -0
  44. stataflow-0.1.0/tests/test_ols_against_statsmodels.py +178 -0
  45. stataflow-0.1.0/tests/test_rdrobust.py +262 -0
  46. stataflow-0.1.0/tests/test_result_schema.py +140 -0
  47. stataflow-0.1.0/tests/test_smoke.py +19 -0
  48. stataflow-0.1.0/tests/test_stata_runner.py +110 -0
  49. stataflow-0.1.0/tests/test_validation_summary.py +34 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zhenhao Fu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: StataFlow
3
+ Version: 0.1.0
4
+ Summary: Stata2Python: A Python econometrics toolkit aligned with Stata 17
5
+ Author-email: Zhenhao Fu <zhenhaofu2001@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ZhenHaoFu810/StataFlow
8
+ Project-URL: Repository, https://github.com/ZhenHaoFu810/StataFlow
9
+ Project-URL: Issues, https://github.com/ZhenHaoFu810/StataFlow/issues
10
+ Keywords: econometrics,stata,regression,fixed-effects,panel-data
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.24
23
+ Requires-Dist: pandas>=2.0
24
+ Requires-Dist: scipy>=1.10
25
+ Requires-Dist: pyyaml>=6.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # Stata2Python
32
+
33
+ Stata2Python (`statapy`) is a Python econometrics toolkit that reproduces Stata 17 estimation results with high precision. It provides both a **Stata-compatible command layer** (for researchers migrating from Stata) and a **native Python estimator layer** (for advanced users who want direct control).
34
+
35
+ ## What you can do today
36
+
37
+ - Run Stata-style commands in Python: `regress`, `reghdfe`, `ivregress 2sls`, `logit`, `ppmlhdfe`, `did_imputation`, `csdid`, `rdrobust`, and more.
38
+ - Obtain coefficients, standard errors, t/z-statistics, p-values, and confidence intervals that are field-level verified against Stata 17.
39
+ - Work with high-dimensional fixed effects (HDFE), IV/2SLS, binary/count models, and DID/event-study estimators.
40
+ - Use Stata-style factor-variable syntax (`i.group##c.post`, `c.x1#c.x2`, `x1##x2`) and space-separated absorb strings directly in wrapper commands. Bare variables inside `#` / `##` are treated as continuous, matching common Stata usage.
41
+
42
+ ## What is not yet supported
43
+
44
+ - **Multi-way clustering** — only single-cluster robust inference is available.
45
+ - **Direct post-estimation on wrapper returns** — the `compat.stata` wrappers return `ResultSchema` result objects. `predict` and `margins` are available on the core estimator layer only.
46
+ - **Full command surfaces for community commands** — `reghdfe`, `ivreghdfe`, `ppmlhdfe`, `did_imputation`, `eventstudyinteract`, `csdid`, and `rdrobust` are implemented as **verified high-frequency subsets**, not complete Stata command reproductions. Unsupported options are explicitly rejected rather than silently ignored.
47
+
48
+ ### Completeness legend
49
+
50
+ - **Stable** — synthetic + real-data dual-run verified; core API is unlikely to change.
51
+ - **Alpha** — high-frequency paths are implemented and verified, but the command surface is still a subset of the full Stata community command.
52
+ - **Alpha — Partial** — a verifiable implementation exists, but large functional areas are still missing (e.g., fuzzy RD for `rdrobust`, multi-way clustering).
53
+
54
+ See the [Command Support Matrix](./docs/command-support-matrix/README.md) for the per-command detailed status.
55
+ For the public Stata-vs-Python evidence book, see [Validation Overview](./docs/validation/overview.md).
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install -e .
63
+ ```
64
+
65
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
66
+
67
+ ---
68
+
69
+ ## Quick start
70
+
71
+ ### Stata-compatible command layer (recommended)
72
+
73
+ All `compat.stata` wrappers return a `ResultSchema` object with coefficients, standard errors, and fit statistics. They do **not** expose `.predict()` or `.margins()` directly—use the core estimator layer below for post-estimation.
74
+
75
+ ```python
76
+ import pandas as pd
77
+ from statapy.compat.stata import regress, reghdfe, ivregress_2sls, logit
78
+
79
+ # OLS with robust standard errors
80
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
81
+
82
+ # High-dimensional fixed effects (reghdfe)
83
+ result = reghdfe(
84
+ df, y="wage", x=["edu", "exper"],
85
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
86
+ )
87
+
88
+ # Factor-variable syntax in HDFE
89
+ result = reghdfe(
90
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
91
+ )
92
+
93
+ # 2SLS
94
+ result = ivregress_2sls(
95
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
96
+ instruments=["age", "kidslt6"], vce="robust"
97
+ )
98
+
99
+ # Logit
100
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
101
+ ```
102
+
103
+ For runnable examples, see the [`examples/`](./examples/) directory:
104
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
105
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
106
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
107
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
108
+
109
+ ### Native Python estimator layer (advanced)
110
+
111
+ ```python
112
+ from statapy import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
113
+
114
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
115
+ result = model.fit(vce="robust")
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Supported commands
121
+
122
+ | Command | Python entry | Core capabilities |
123
+ |---------|--------------|-------------------|
124
+ | `regress` | `statapy.compat.stata.regress` | OLS, robust, cluster, aweight |
125
+ | `xtreg, fe` | `statapy.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
126
+ | `areg` | `statapy.compat.stata.areg` | Single absorb variable FE |
127
+ | `reghdfe` | `statapy.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
128
+ | `ivregress 2sls` | `statapy.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
129
+ | `ivreghdfe` | `statapy.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
130
+ | `logit` | `statapy.compat.stata.logit` | MLE, robust, cluster |
131
+ | `probit` | `statapy.compat.stata.probit` | MLE, robust, cluster |
132
+ | `poisson` | `statapy.compat.stata.poisson` | MLE, robust, cluster |
133
+ | `ppmlhdfe` | `statapy.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
134
+ | `did_imputation` | `statapy.compat.stata.did_imputation` | BJS DID imputation |
135
+ | `eventstudyinteract` | `statapy.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
136
+ | `csdid` | `statapy.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
137
+ | `rdrobust` | `statapy.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
138
+
139
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
140
+
141
+ ---
142
+
143
+ ## Validation philosophy
144
+
145
+ Every public command is validated with **two lines of evidence**:
146
+
147
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
148
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
149
+
150
+ A command is considered "done" only when both lines pass and the source-to-Python mapping is documented. We do not accept "statistical equivalence" without explicit mathematical or source-code justification.
151
+
152
+ Public evidence entry points:
153
+
154
+ - [Validation Overview](./docs/validation/overview.md)
155
+ - [Evidence Matrix](./docs/validation/evidence-matrix.md)
156
+ - [Dataset Registry](./docs/validation/dataset-registry.md)
157
+ - [Validation Policy](./docs/validation/validation-policy.md)
158
+
159
+ ### Running tests
160
+
161
+ ```bash
162
+ # Unit and integration tests (fast)
163
+ pytest tests/ -v --ignore=tests/golden/
164
+
165
+ # Golden dual-run tests (require Stata 17)
166
+ pytest tests/golden/ -v
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Project structure
172
+
173
+ - **`src/statapy/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
174
+ - **`src/statapy/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
175
+ - **`docs/research/`** — Source-to-Python mapping documents for community commands
176
+ - **`docs/command-support-matrix/`** — Per-command support matrices
177
+ - **`tests/golden/`** — Stata-Python dual-run tests
178
+ - **`research/vendor/stata_community/`** — Local mirrors of open-source Stata community packages (for research only)
179
+
180
+ ---
181
+
182
+ ## Default target version
183
+
184
+ **Stata 17**
185
+
186
+ ---
187
+
188
+ ## Documentation
189
+
190
+ - [Project charter](./docs/project-charter.md)
191
+ - [Architecture overview](./docs/architecture/overview.md)
192
+ - [Public API specification](./docs/architecture/public-api.md)
193
+ - [Command support matrices](./docs/command-support-matrix/README.md)
194
+ - [Validation overview](./docs/validation/overview.md)
195
+ - [Validation evidence matrix](./docs/validation/evidence-matrix.md)
196
+ - [Open-source roadmap](./docs/next-round-open-source-plan.md)
197
+
198
+ ---
199
+
200
+ ## Governance
201
+
202
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
203
+ - **Claude Code** — implementation, testing, and evidence backfill.
@@ -0,0 +1,173 @@
1
+ # Stata2Python
2
+
3
+ Stata2Python (`statapy`) is a Python econometrics toolkit that reproduces Stata 17 estimation results with high precision. It provides both a **Stata-compatible command layer** (for researchers migrating from Stata) and a **native Python estimator layer** (for advanced users who want direct control).
4
+
5
+ ## What you can do today
6
+
7
+ - Run Stata-style commands in Python: `regress`, `reghdfe`, `ivregress 2sls`, `logit`, `ppmlhdfe`, `did_imputation`, `csdid`, `rdrobust`, and more.
8
+ - Obtain coefficients, standard errors, t/z-statistics, p-values, and confidence intervals that are field-level verified against Stata 17.
9
+ - Work with high-dimensional fixed effects (HDFE), IV/2SLS, binary/count models, and DID/event-study estimators.
10
+ - Use Stata-style factor-variable syntax (`i.group##c.post`, `c.x1#c.x2`, `x1##x2`) and space-separated absorb strings directly in wrapper commands. Bare variables inside `#` / `##` are treated as continuous, matching common Stata usage.
11
+
12
+ ## What is not yet supported
13
+
14
+ - **Multi-way clustering** — only single-cluster robust inference is available.
15
+ - **Direct post-estimation on wrapper returns** — the `compat.stata` wrappers return `ResultSchema` result objects. `predict` and `margins` are available on the core estimator layer only.
16
+ - **Full command surfaces for community commands** — `reghdfe`, `ivreghdfe`, `ppmlhdfe`, `did_imputation`, `eventstudyinteract`, `csdid`, and `rdrobust` are implemented as **verified high-frequency subsets**, not complete Stata command reproductions. Unsupported options are explicitly rejected rather than silently ignored.
17
+
18
+ ### Completeness legend
19
+
20
+ - **Stable** — synthetic + real-data dual-run verified; core API is unlikely to change.
21
+ - **Alpha** — high-frequency paths are implemented and verified, but the command surface is still a subset of the full Stata community command.
22
+ - **Alpha — Partial** — a verifiable implementation exists, but large functional areas are still missing (e.g., fuzzy RD for `rdrobust`, multi-way clustering).
23
+
24
+ See the [Command Support Matrix](./docs/command-support-matrix/README.md) for the per-command detailed status.
25
+ For the public Stata-vs-Python evidence book, see [Validation Overview](./docs/validation/overview.md).
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install -e .
33
+ ```
34
+
35
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
36
+
37
+ ---
38
+
39
+ ## Quick start
40
+
41
+ ### Stata-compatible command layer (recommended)
42
+
43
+ All `compat.stata` wrappers return a `ResultSchema` object with coefficients, standard errors, and fit statistics. They do **not** expose `.predict()` or `.margins()` directly—use the core estimator layer below for post-estimation.
44
+
45
+ ```python
46
+ import pandas as pd
47
+ from statapy.compat.stata import regress, reghdfe, ivregress_2sls, logit
48
+
49
+ # OLS with robust standard errors
50
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
51
+
52
+ # High-dimensional fixed effects (reghdfe)
53
+ result = reghdfe(
54
+ df, y="wage", x=["edu", "exper"],
55
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
56
+ )
57
+
58
+ # Factor-variable syntax in HDFE
59
+ result = reghdfe(
60
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
61
+ )
62
+
63
+ # 2SLS
64
+ result = ivregress_2sls(
65
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
66
+ instruments=["age", "kidslt6"], vce="robust"
67
+ )
68
+
69
+ # Logit
70
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
71
+ ```
72
+
73
+ For runnable examples, see the [`examples/`](./examples/) directory:
74
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
75
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
76
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
77
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
78
+
79
+ ### Native Python estimator layer (advanced)
80
+
81
+ ```python
82
+ from statapy import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
83
+
84
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
85
+ result = model.fit(vce="robust")
86
+ ```
87
+
88
+ ---
89
+
90
+ ## Supported commands
91
+
92
+ | Command | Python entry | Core capabilities |
93
+ |---------|--------------|-------------------|
94
+ | `regress` | `statapy.compat.stata.regress` | OLS, robust, cluster, aweight |
95
+ | `xtreg, fe` | `statapy.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
96
+ | `areg` | `statapy.compat.stata.areg` | Single absorb variable FE |
97
+ | `reghdfe` | `statapy.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
98
+ | `ivregress 2sls` | `statapy.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
99
+ | `ivreghdfe` | `statapy.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
100
+ | `logit` | `statapy.compat.stata.logit` | MLE, robust, cluster |
101
+ | `probit` | `statapy.compat.stata.probit` | MLE, robust, cluster |
102
+ | `poisson` | `statapy.compat.stata.poisson` | MLE, robust, cluster |
103
+ | `ppmlhdfe` | `statapy.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
104
+ | `did_imputation` | `statapy.compat.stata.did_imputation` | BJS DID imputation |
105
+ | `eventstudyinteract` | `statapy.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
106
+ | `csdid` | `statapy.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
107
+ | `rdrobust` | `statapy.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
108
+
109
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
110
+
111
+ ---
112
+
113
+ ## Validation philosophy
114
+
115
+ Every public command is validated with **two lines of evidence**:
116
+
117
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
118
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
119
+
120
+ A command is considered "done" only when both lines pass and the source-to-Python mapping is documented. We do not accept "statistical equivalence" without explicit mathematical or source-code justification.
121
+
122
+ Public evidence entry points:
123
+
124
+ - [Validation Overview](./docs/validation/overview.md)
125
+ - [Evidence Matrix](./docs/validation/evidence-matrix.md)
126
+ - [Dataset Registry](./docs/validation/dataset-registry.md)
127
+ - [Validation Policy](./docs/validation/validation-policy.md)
128
+
129
+ ### Running tests
130
+
131
+ ```bash
132
+ # Unit and integration tests (fast)
133
+ pytest tests/ -v --ignore=tests/golden/
134
+
135
+ # Golden dual-run tests (require Stata 17)
136
+ pytest tests/golden/ -v
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Project structure
142
+
143
+ - **`src/statapy/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
144
+ - **`src/statapy/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
145
+ - **`docs/research/`** — Source-to-Python mapping documents for community commands
146
+ - **`docs/command-support-matrix/`** — Per-command support matrices
147
+ - **`tests/golden/`** — Stata-Python dual-run tests
148
+ - **`research/vendor/stata_community/`** — Local mirrors of open-source Stata community packages (for research only)
149
+
150
+ ---
151
+
152
+ ## Default target version
153
+
154
+ **Stata 17**
155
+
156
+ ---
157
+
158
+ ## Documentation
159
+
160
+ - [Project charter](./docs/project-charter.md)
161
+ - [Architecture overview](./docs/architecture/overview.md)
162
+ - [Public API specification](./docs/architecture/public-api.md)
163
+ - [Command support matrices](./docs/command-support-matrix/README.md)
164
+ - [Validation overview](./docs/validation/overview.md)
165
+ - [Validation evidence matrix](./docs/validation/evidence-matrix.md)
166
+ - [Open-source roadmap](./docs/next-round-open-source-plan.md)
167
+
168
+ ---
169
+
170
+ ## Governance
171
+
172
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
173
+ - **Claude Code** — implementation, testing, and evidence backfill.
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "StataFlow"
7
+ version = "0.1.0"
8
+ description = "Stata2Python: A Python econometrics toolkit aligned with Stata 17"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ authors = [{name = "Zhenhao Fu", email = "zhenhaofu2001@gmail.com"}]
12
+ keywords = ["econometrics", "stata", "regression", "fixed-effects", "panel-data"]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Science/Research",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Scientific/Engineering :: Mathematics",
22
+ ]
23
+ requires-python = ">=3.10"
24
+ dependencies = [
25
+ "numpy>=1.24",
26
+ "pandas>=2.0",
27
+ "scipy>=1.10",
28
+ "pyyaml>=6.0",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=7.0",
34
+ "pytest-cov>=4.0",
35
+ ]
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/ZhenHaoFu810/StataFlow"
39
+ Repository = "https://github.com/ZhenHaoFu810/StataFlow"
40
+ Issues = "https://github.com/ZhenHaoFu810/StataFlow/issues"
41
+
42
+ [tool.setuptools.packages.find]
43
+ where = ["src"]
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
47
+ addopts = "-v --tb=short"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.4
2
+ Name: StataFlow
3
+ Version: 0.1.0
4
+ Summary: Stata2Python: A Python econometrics toolkit aligned with Stata 17
5
+ Author-email: Zhenhao Fu <zhenhaofu2001@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ZhenHaoFu810/StataFlow
8
+ Project-URL: Repository, https://github.com/ZhenHaoFu810/StataFlow
9
+ Project-URL: Issues, https://github.com/ZhenHaoFu810/StataFlow/issues
10
+ Keywords: econometrics,stata,regression,fixed-effects,panel-data
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: numpy>=1.24
23
+ Requires-Dist: pandas>=2.0
24
+ Requires-Dist: scipy>=1.10
25
+ Requires-Dist: pyyaml>=6.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # Stata2Python
32
+
33
+ Stata2Python (`statapy`) is a Python econometrics toolkit that reproduces Stata 17 estimation results with high precision. It provides both a **Stata-compatible command layer** (for researchers migrating from Stata) and a **native Python estimator layer** (for advanced users who want direct control).
34
+
35
+ ## What you can do today
36
+
37
+ - Run Stata-style commands in Python: `regress`, `reghdfe`, `ivregress 2sls`, `logit`, `ppmlhdfe`, `did_imputation`, `csdid`, `rdrobust`, and more.
38
+ - Obtain coefficients, standard errors, t/z-statistics, p-values, and confidence intervals that are field-level verified against Stata 17.
39
+ - Work with high-dimensional fixed effects (HDFE), IV/2SLS, binary/count models, and DID/event-study estimators.
40
+ - Use Stata-style factor-variable syntax (`i.group##c.post`, `c.x1#c.x2`, `x1##x2`) and space-separated absorb strings directly in wrapper commands. Bare variables inside `#` / `##` are treated as continuous, matching common Stata usage.
41
+
42
+ ## What is not yet supported
43
+
44
+ - **Multi-way clustering** — only single-cluster robust inference is available.
45
+ - **Direct post-estimation on wrapper returns** — the `compat.stata` wrappers return `ResultSchema` result objects. `predict` and `margins` are available on the core estimator layer only.
46
+ - **Full command surfaces for community commands** — `reghdfe`, `ivreghdfe`, `ppmlhdfe`, `did_imputation`, `eventstudyinteract`, `csdid`, and `rdrobust` are implemented as **verified high-frequency subsets**, not complete Stata command reproductions. Unsupported options are explicitly rejected rather than silently ignored.
47
+
48
+ ### Completeness legend
49
+
50
+ - **Stable** — synthetic + real-data dual-run verified; core API is unlikely to change.
51
+ - **Alpha** — high-frequency paths are implemented and verified, but the command surface is still a subset of the full Stata community command.
52
+ - **Alpha — Partial** — a verifiable implementation exists, but large functional areas are still missing (e.g., fuzzy RD for `rdrobust`, multi-way clustering).
53
+
54
+ See the [Command Support Matrix](./docs/command-support-matrix/README.md) for the per-command detailed status.
55
+ For the public Stata-vs-Python evidence book, see [Validation Overview](./docs/validation/overview.md).
56
+
57
+ ---
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install -e .
63
+ ```
64
+
65
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
66
+
67
+ ---
68
+
69
+ ## Quick start
70
+
71
+ ### Stata-compatible command layer (recommended)
72
+
73
+ All `compat.stata` wrappers return a `ResultSchema` object with coefficients, standard errors, and fit statistics. They do **not** expose `.predict()` or `.margins()` directly—use the core estimator layer below for post-estimation.
74
+
75
+ ```python
76
+ import pandas as pd
77
+ from statapy.compat.stata import regress, reghdfe, ivregress_2sls, logit
78
+
79
+ # OLS with robust standard errors
80
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
81
+
82
+ # High-dimensional fixed effects (reghdfe)
83
+ result = reghdfe(
84
+ df, y="wage", x=["edu", "exper"],
85
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
86
+ )
87
+
88
+ # Factor-variable syntax in HDFE
89
+ result = reghdfe(
90
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
91
+ )
92
+
93
+ # 2SLS
94
+ result = ivregress_2sls(
95
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
96
+ instruments=["age", "kidslt6"], vce="robust"
97
+ )
98
+
99
+ # Logit
100
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
101
+ ```
102
+
103
+ For runnable examples, see the [`examples/`](./examples/) directory:
104
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
105
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
106
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
107
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
108
+
109
+ ### Native Python estimator layer (advanced)
110
+
111
+ ```python
112
+ from statapy import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
113
+
114
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
115
+ result = model.fit(vce="robust")
116
+ ```
117
+
118
+ ---
119
+
120
+ ## Supported commands
121
+
122
+ | Command | Python entry | Core capabilities |
123
+ |---------|--------------|-------------------|
124
+ | `regress` | `statapy.compat.stata.regress` | OLS, robust, cluster, aweight |
125
+ | `xtreg, fe` | `statapy.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
126
+ | `areg` | `statapy.compat.stata.areg` | Single absorb variable FE |
127
+ | `reghdfe` | `statapy.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
128
+ | `ivregress 2sls` | `statapy.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
129
+ | `ivreghdfe` | `statapy.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
130
+ | `logit` | `statapy.compat.stata.logit` | MLE, robust, cluster |
131
+ | `probit` | `statapy.compat.stata.probit` | MLE, robust, cluster |
132
+ | `poisson` | `statapy.compat.stata.poisson` | MLE, robust, cluster |
133
+ | `ppmlhdfe` | `statapy.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
134
+ | `did_imputation` | `statapy.compat.stata.did_imputation` | BJS DID imputation |
135
+ | `eventstudyinteract` | `statapy.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
136
+ | `csdid` | `statapy.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
137
+ | `rdrobust` | `statapy.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
138
+
139
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
140
+
141
+ ---
142
+
143
+ ## Validation philosophy
144
+
145
+ Every public command is validated with **two lines of evidence**:
146
+
147
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
148
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
149
+
150
+ A command is considered "done" only when both lines pass and the source-to-Python mapping is documented. We do not accept "statistical equivalence" without explicit mathematical or source-code justification.
151
+
152
+ Public evidence entry points:
153
+
154
+ - [Validation Overview](./docs/validation/overview.md)
155
+ - [Evidence Matrix](./docs/validation/evidence-matrix.md)
156
+ - [Dataset Registry](./docs/validation/dataset-registry.md)
157
+ - [Validation Policy](./docs/validation/validation-policy.md)
158
+
159
+ ### Running tests
160
+
161
+ ```bash
162
+ # Unit and integration tests (fast)
163
+ pytest tests/ -v --ignore=tests/golden/
164
+
165
+ # Golden dual-run tests (require Stata 17)
166
+ pytest tests/golden/ -v
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Project structure
172
+
173
+ - **`src/statapy/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
174
+ - **`src/statapy/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
175
+ - **`docs/research/`** — Source-to-Python mapping documents for community commands
176
+ - **`docs/command-support-matrix/`** — Per-command support matrices
177
+ - **`tests/golden/`** — Stata-Python dual-run tests
178
+ - **`research/vendor/stata_community/`** — Local mirrors of open-source Stata community packages (for research only)
179
+
180
+ ---
181
+
182
+ ## Default target version
183
+
184
+ **Stata 17**
185
+
186
+ ---
187
+
188
+ ## Documentation
189
+
190
+ - [Project charter](./docs/project-charter.md)
191
+ - [Architecture overview](./docs/architecture/overview.md)
192
+ - [Public API specification](./docs/architecture/public-api.md)
193
+ - [Command support matrices](./docs/command-support-matrix/README.md)
194
+ - [Validation overview](./docs/validation/overview.md)
195
+ - [Validation evidence matrix](./docs/validation/evidence-matrix.md)
196
+ - [Open-source roadmap](./docs/next-round-open-source-plan.md)
197
+
198
+ ---
199
+
200
+ ## Governance
201
+
202
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
203
+ - **Claude Code** — implementation, testing, and evidence backfill.