StataFlow 0.1.2__tar.gz → 0.1.4__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 (54) hide show
  1. stataflow-0.1.4/PKG-INFO +202 -0
  2. stataflow-0.1.4/README.md +172 -0
  3. {stataflow-0.1.2 → stataflow-0.1.4}/pyproject.toml +4 -3
  4. stataflow-0.1.4/src/StataFlow.egg-info/PKG-INFO +202 -0
  5. stataflow-0.1.4/src/StataFlow.egg-info/SOURCES.txt +47 -0
  6. stataflow-0.1.4/src/StataFlow.egg-info/top_level.txt +1 -0
  7. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/__init__.py +74 -74
  8. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/__init__.py +1 -1
  9. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/did.py +4 -4
  10. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/glm.py +7 -7
  11. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/hdfe.py +4 -4
  12. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/iv.py +4 -4
  13. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/linear.py +5 -5
  14. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/rdrobust.py +2 -2
  15. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/absorbing_ols.py +2 -2
  16. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/csdid.py +1 -1
  17. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/did_imputation.py +1 -1
  18. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/eventstudyinteract.py +1 -1
  19. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/fe.py +2 -2
  20. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/glm.py +2 -2
  21. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/iv.py +2 -2
  22. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/ols.py +7 -7
  23. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/ppmlhdfe.py +4 -4
  24. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/rdrobust.py +2 -2
  25. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_compat_stata_did.py +2 -2
  26. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_compat_stata_glm.py +2 -2
  27. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_compat_stata_hdfe.py +2 -2
  28. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_compat_stata_iv.py +2 -2
  29. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_compat_stata_linear.py +2 -2
  30. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_factor_variables.py +2 -2
  31. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_hdfe_synthetic.py +2 -2
  32. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_ols_against_statsmodels.py +1 -1
  33. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_rdrobust.py +8 -8
  34. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_result_schema.py +1 -1
  35. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_smoke.py +6 -6
  36. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_stata_runner.py +1 -1
  37. stataflow-0.1.2/PKG-INFO +0 -144
  38. stataflow-0.1.2/README.md +0 -115
  39. stataflow-0.1.2/src/StataFlow.egg-info/PKG-INFO +0 -144
  40. stataflow-0.1.2/src/StataFlow.egg-info/SOURCES.txt +0 -47
  41. stataflow-0.1.2/src/StataFlow.egg-info/top_level.txt +0 -1
  42. {stataflow-0.1.2 → stataflow-0.1.4}/LICENSE +0 -0
  43. {stataflow-0.1.2 → stataflow-0.1.4}/setup.cfg +0 -0
  44. {stataflow-0.1.2 → stataflow-0.1.4}/src/StataFlow.egg-info/dependency_links.txt +0 -0
  45. {stataflow-0.1.2 → stataflow-0.1.4}/src/StataFlow.egg-info/requires.txt +0 -0
  46. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/__init__.py +0 -0
  47. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/compat/stata/factor_variables.py +0 -0
  48. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/estimators/__init__.py +0 -0
  49. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/postestimation.py +0 -0
  50. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/results/__init__.py +0 -0
  51. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/results/result.py +0 -0
  52. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/stata_runner/__init__.py +0 -0
  53. {stataflow-0.1.2/src/statapy → stataflow-0.1.4/src/stataflow}/stata_runner/runner.py +0 -0
  54. {stataflow-0.1.2 → stataflow-0.1.4}/tests/test_validation_summary.py +0 -0
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: StataFlow
3
+ Version: 0.1.4
4
+ Summary: StataFlow: 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
+ # StataFlow
32
+
33
+ StataFlow (`stataflow`) 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
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install StataFlow
62
+ ```
63
+
64
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
65
+
66
+ For development (editable install from source):
67
+
68
+ ```bash
69
+ git clone https://github.com/ZhenHaoFu810/StataFlow.git
70
+ cd StataFlow
71
+ pip install -e .
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Quick start
77
+
78
+ ### Stata-compatible command layer (recommended)
79
+
80
+ 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.
81
+
82
+ ```python
83
+ import pandas as pd
84
+ from stataflow.compat.stata import regress, reghdfe, ivregress_2sls, logit
85
+
86
+ # OLS with robust standard errors
87
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
88
+
89
+ # High-dimensional fixed effects (reghdfe)
90
+ result = reghdfe(
91
+ df, y="wage", x=["edu", "exper"],
92
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
93
+ )
94
+
95
+ # Factor-variable syntax in HDFE
96
+ result = reghdfe(
97
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
98
+ )
99
+
100
+ # 2SLS
101
+ result = ivregress_2sls(
102
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
103
+ instruments=["age", "kidslt6"], vce="robust"
104
+ )
105
+
106
+ # Logit
107
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
108
+ ```
109
+
110
+ For runnable examples, see the [`examples/`](./examples/) directory:
111
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
112
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
113
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
114
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
115
+
116
+ ### Native Python estimator layer (advanced)
117
+
118
+ ```python
119
+ from stataflow import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
120
+
121
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
122
+ result = model.fit(vce="robust")
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Supported commands
128
+
129
+ | Command | Python entry | Core capabilities |
130
+ |---------|--------------|-------------------|
131
+ | `regress` | `stataflow.compat.stata.regress` | OLS, robust, cluster, aweight |
132
+ | `xtreg, fe` | `stataflow.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
133
+ | `areg` | `stataflow.compat.stata.areg` | Single absorb variable FE |
134
+ | `reghdfe` | `stataflow.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
135
+ | `ivregress 2sls` | `stataflow.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
136
+ | `ivreghdfe` | `stataflow.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
137
+ | `logit` | `stataflow.compat.stata.logit` | MLE, robust, cluster |
138
+ | `probit` | `stataflow.compat.stata.probit` | MLE, robust, cluster |
139
+ | `poisson` | `stataflow.compat.stata.poisson` | MLE, robust, cluster |
140
+ | `ppmlhdfe` | `stataflow.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
141
+ | `did_imputation` | `stataflow.compat.stata.did_imputation` | BJS DID imputation |
142
+ | `eventstudyinteract` | `stataflow.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
143
+ | `csdid` | `stataflow.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
144
+ | `rdrobust` | `stataflow.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
145
+
146
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
147
+
148
+ ---
149
+
150
+ ## Validation philosophy
151
+
152
+ Every public command is validated with **two lines of evidence**:
153
+
154
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
155
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
156
+
157
+ 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.
158
+
159
+ Public evidence and results are available in `research/results/validation/`.
160
+
161
+ ### Running tests
162
+
163
+ ```bash
164
+ # Unit and integration tests (fast)
165
+ pytest tests/ -v --ignore=tests/golden/
166
+
167
+ # Golden dual-run tests (require Stata 17)
168
+ pytest tests/golden/ -v
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Project structure
174
+
175
+ - **`src/stataflow/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
176
+ - **`src/stataflow/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
177
+ - **`docs/command-support-matrix/`** — Per-command support matrices
178
+ - **`examples/`** — Runnable demonstration scripts
179
+ - **`tests/`** — Unit and integration tests
180
+
181
+ ---
182
+
183
+ ## Default target version
184
+
185
+ **Stata 17**
186
+
187
+ ---
188
+
189
+ ## Documentation
190
+
191
+ - [User guide](./docs/USER_GUIDE.md)
192
+ - [Chinese user guide](./docs/USER_GUIDE.zh-CN.md)
193
+ - [Cookbook](./docs/cookbook.md)
194
+ - [Chinese cookbook](./docs/cookbook.zh-CN.md)
195
+ - [Command support matrices](./docs/command-support-matrix/README.md)
196
+
197
+ ---
198
+
199
+ ## Governance
200
+
201
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
202
+ - **Claude Code** — implementation, testing, and evidence backfill.
@@ -0,0 +1,172 @@
1
+ # StataFlow
2
+
3
+ StataFlow (`stataflow`) 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
+
26
+ ---
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pip install StataFlow
32
+ ```
33
+
34
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
35
+
36
+ For development (editable install from source):
37
+
38
+ ```bash
39
+ git clone https://github.com/ZhenHaoFu810/StataFlow.git
40
+ cd StataFlow
41
+ pip install -e .
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Quick start
47
+
48
+ ### Stata-compatible command layer (recommended)
49
+
50
+ 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.
51
+
52
+ ```python
53
+ import pandas as pd
54
+ from stataflow.compat.stata import regress, reghdfe, ivregress_2sls, logit
55
+
56
+ # OLS with robust standard errors
57
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
58
+
59
+ # High-dimensional fixed effects (reghdfe)
60
+ result = reghdfe(
61
+ df, y="wage", x=["edu", "exper"],
62
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
63
+ )
64
+
65
+ # Factor-variable syntax in HDFE
66
+ result = reghdfe(
67
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
68
+ )
69
+
70
+ # 2SLS
71
+ result = ivregress_2sls(
72
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
73
+ instruments=["age", "kidslt6"], vce="robust"
74
+ )
75
+
76
+ # Logit
77
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
78
+ ```
79
+
80
+ For runnable examples, see the [`examples/`](./examples/) directory:
81
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
82
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
83
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
84
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
85
+
86
+ ### Native Python estimator layer (advanced)
87
+
88
+ ```python
89
+ from stataflow import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
90
+
91
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
92
+ result = model.fit(vce="robust")
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Supported commands
98
+
99
+ | Command | Python entry | Core capabilities |
100
+ |---------|--------------|-------------------|
101
+ | `regress` | `stataflow.compat.stata.regress` | OLS, robust, cluster, aweight |
102
+ | `xtreg, fe` | `stataflow.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
103
+ | `areg` | `stataflow.compat.stata.areg` | Single absorb variable FE |
104
+ | `reghdfe` | `stataflow.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
105
+ | `ivregress 2sls` | `stataflow.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
106
+ | `ivreghdfe` | `stataflow.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
107
+ | `logit` | `stataflow.compat.stata.logit` | MLE, robust, cluster |
108
+ | `probit` | `stataflow.compat.stata.probit` | MLE, robust, cluster |
109
+ | `poisson` | `stataflow.compat.stata.poisson` | MLE, robust, cluster |
110
+ | `ppmlhdfe` | `stataflow.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
111
+ | `did_imputation` | `stataflow.compat.stata.did_imputation` | BJS DID imputation |
112
+ | `eventstudyinteract` | `stataflow.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
113
+ | `csdid` | `stataflow.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
114
+ | `rdrobust` | `stataflow.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
115
+
116
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
117
+
118
+ ---
119
+
120
+ ## Validation philosophy
121
+
122
+ Every public command is validated with **two lines of evidence**:
123
+
124
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
125
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
126
+
127
+ 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.
128
+
129
+ Public evidence and results are available in `research/results/validation/`.
130
+
131
+ ### Running tests
132
+
133
+ ```bash
134
+ # Unit and integration tests (fast)
135
+ pytest tests/ -v --ignore=tests/golden/
136
+
137
+ # Golden dual-run tests (require Stata 17)
138
+ pytest tests/golden/ -v
139
+ ```
140
+
141
+ ---
142
+
143
+ ## Project structure
144
+
145
+ - **`src/stataflow/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
146
+ - **`src/stataflow/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
147
+ - **`docs/command-support-matrix/`** — Per-command support matrices
148
+ - **`examples/`** — Runnable demonstration scripts
149
+ - **`tests/`** — Unit and integration tests
150
+
151
+ ---
152
+
153
+ ## Default target version
154
+
155
+ **Stata 17**
156
+
157
+ ---
158
+
159
+ ## Documentation
160
+
161
+ - [User guide](./docs/USER_GUIDE.md)
162
+ - [Chinese user guide](./docs/USER_GUIDE.zh-CN.md)
163
+ - [Cookbook](./docs/cookbook.md)
164
+ - [Chinese cookbook](./docs/cookbook.zh-CN.md)
165
+ - [Command support matrices](./docs/command-support-matrix/README.md)
166
+
167
+ ---
168
+
169
+ ## Governance
170
+
171
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
172
+ - **Claude Code** — implementation, testing, and evidence backfill.
@@ -4,15 +4,16 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "StataFlow"
7
- version = "0.1.2"
8
- description = "Stata2Python: A Python econometrics toolkit aligned with Stata 17"
7
+ version = "0.1.4"
8
+ description = "StataFlow: A Python econometrics toolkit aligned with Stata 17"
9
9
  readme = "README.md"
10
- license = "MIT"
10
+ license = {text = "MIT"}
11
11
  authors = [{name = "Zhenhao Fu", email = "zhenhaofu2001@gmail.com"}]
12
12
  keywords = ["econometrics", "stata", "regression", "fixed-effects", "panel-data"]
13
13
  classifiers = [
14
14
  "Development Status :: 3 - Alpha",
15
15
  "Intended Audience :: Science/Research",
16
+ "License :: OSI Approved :: MIT License",
16
17
  "Programming Language :: Python :: 3",
17
18
  "Programming Language :: Python :: 3.10",
18
19
  "Programming Language :: Python :: 3.11",
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: StataFlow
3
+ Version: 0.1.4
4
+ Summary: StataFlow: 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
+ # StataFlow
32
+
33
+ StataFlow (`stataflow`) 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
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install StataFlow
62
+ ```
63
+
64
+ Requirements: Python 3.10+, NumPy, pandas, SciPy.
65
+
66
+ For development (editable install from source):
67
+
68
+ ```bash
69
+ git clone https://github.com/ZhenHaoFu810/StataFlow.git
70
+ cd StataFlow
71
+ pip install -e .
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Quick start
77
+
78
+ ### Stata-compatible command layer (recommended)
79
+
80
+ 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.
81
+
82
+ ```python
83
+ import pandas as pd
84
+ from stataflow.compat.stata import regress, reghdfe, ivregress_2sls, logit
85
+
86
+ # OLS with robust standard errors
87
+ result = regress(df, y="wage", x=["edu", "exper"], vce="robust")
88
+
89
+ # High-dimensional fixed effects (reghdfe)
90
+ result = reghdfe(
91
+ df, y="wage", x=["edu", "exper"],
92
+ absorb="firm_id year_id", vce="cluster", cluster="industry"
93
+ )
94
+
95
+ # Factor-variable syntax in HDFE
96
+ result = reghdfe(
97
+ df, y="wage", x=["i.industry##c.post"], absorb="firm_id year_id"
98
+ )
99
+
100
+ # 2SLS
101
+ result = ivregress_2sls(
102
+ df, y="lwage", x_exog=["edu"], x_endog=["exper"],
103
+ instruments=["age", "kidslt6"], vce="robust"
104
+ )
105
+
106
+ # Logit
107
+ result = logit(df, y="inlf", x=["nwifeinc", "educ", "exper"])
108
+ ```
109
+
110
+ For runnable examples, see the [`examples/`](./examples/) directory:
111
+ - [`examples/demo_regress.py`](./examples/demo_regress.py)
112
+ - [`examples/demo_reghdfe.py`](./examples/demo_reghdfe.py)
113
+ - [`examples/demo_ppmlhdfe.py`](./examples/demo_ppmlhdfe.py)
114
+ - [`examples/demo_ivregress_2sls.py`](./examples/demo_ivregress_2sls.py)
115
+
116
+ ### Native Python estimator layer (advanced)
117
+
118
+ ```python
119
+ from stataflow import OLS, FixedEffectsOLS, AbsorbingOLS, Logit, IV2SLS
120
+
121
+ model = OLS(data=df, y="wage", x=["edu", "exper"])
122
+ result = model.fit(vce="robust")
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Supported commands
128
+
129
+ | Command | Python entry | Core capabilities |
130
+ |---------|--------------|-------------------|
131
+ | `regress` | `stataflow.compat.stata.regress` | OLS, robust, cluster, aweight |
132
+ | `xtreg, fe` | `stataflow.compat.stata.xtreg_fe` | Fixed effects (within), cluster |
133
+ | `areg` | `stataflow.compat.stata.areg` | Single absorb variable FE |
134
+ | `reghdfe` | `stataflow.compat.stata.reghdfe` | 1-2 group HDFE, cluster, singleton drop |
135
+ | `ivregress 2sls` | `stataflow.compat.stata.ivregress_2sls` | 2SLS, robust, cluster |
136
+ | `ivreghdfe` | `stataflow.compat.stata.ivreghdfe` | IV + 1-2 group HDFE, cluster |
137
+ | `logit` | `stataflow.compat.stata.logit` | MLE, robust, cluster |
138
+ | `probit` | `stataflow.compat.stata.probit` | MLE, robust, cluster |
139
+ | `poisson` | `stataflow.compat.stata.poisson` | MLE, robust, cluster |
140
+ | `ppmlhdfe` | `stataflow.compat.stata.ppmlhdfe` | PPML + 1-2 group HDFE |
141
+ | `did_imputation` | `stataflow.compat.stata.did_imputation` | BJS DID imputation |
142
+ | `eventstudyinteract` | `stataflow.compat.stata.eventstudyinteract` | Sun & Abraham IW estimator |
143
+ | `csdid` | `stataflow.compat.stata.csdid` | Callaway-Sant'Anna DID (`method="reg"` only) |
144
+ | `rdrobust` | `stataflow.compat.stata.rdrobust` | Sharp RD local polynomial (`bwselect="mserd"`, `covs`) |
145
+
146
+ Full details: [`docs/command-support-matrix/README.md`](./docs/command-support-matrix/README.md)
147
+
148
+ ---
149
+
150
+ ## Validation philosophy
151
+
152
+ Every public command is validated with **two lines of evidence**:
153
+
154
+ 1. **Synthetic / controlled cases** — formula, degrees of freedom, sample screening, edge cases.
155
+ 2. **Real public datasets** — field-level comparison against Stata 17 on openly available economic/financial data.
156
+
157
+ 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.
158
+
159
+ Public evidence and results are available in `research/results/validation/`.
160
+
161
+ ### Running tests
162
+
163
+ ```bash
164
+ # Unit and integration tests (fast)
165
+ pytest tests/ -v --ignore=tests/golden/
166
+
167
+ # Golden dual-run tests (require Stata 17)
168
+ pytest tests/golden/ -v
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Project structure
174
+
175
+ - **`src/stataflow/estimators/`** — Core Python estimators (`OLS`, `AbsorbingOLS`, `Logit`, `PPMLHDFE`, `DIDImputation`, etc.)
176
+ - **`src/stataflow/compat/stata/`** — Stata command wrappers (`regress()`, `reghdfe()`, `ivregress_2sls()`, etc.)
177
+ - **`docs/command-support-matrix/`** — Per-command support matrices
178
+ - **`examples/`** — Runnable demonstration scripts
179
+ - **`tests/`** — Unit and integration tests
180
+
181
+ ---
182
+
183
+ ## Default target version
184
+
185
+ **Stata 17**
186
+
187
+ ---
188
+
189
+ ## Documentation
190
+
191
+ - [User guide](./docs/USER_GUIDE.md)
192
+ - [Chinese user guide](./docs/USER_GUIDE.zh-CN.md)
193
+ - [Cookbook](./docs/cookbook.md)
194
+ - [Chinese cookbook](./docs/cookbook.zh-CN.md)
195
+ - [Command support matrices](./docs/command-support-matrix/README.md)
196
+
197
+ ---
198
+
199
+ ## Governance
200
+
201
+ - **Codex** — project goals, architecture, review gates, and statistical-dispute arbitration.
202
+ - **Claude Code** — implementation, testing, and evidence backfill.
@@ -0,0 +1,47 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/StataFlow.egg-info/PKG-INFO
5
+ src/StataFlow.egg-info/SOURCES.txt
6
+ src/StataFlow.egg-info/dependency_links.txt
7
+ src/StataFlow.egg-info/requires.txt
8
+ src/StataFlow.egg-info/top_level.txt
9
+ src/stataflow/__init__.py
10
+ src/stataflow/postestimation.py
11
+ src/stataflow/compat/__init__.py
12
+ src/stataflow/compat/stata/__init__.py
13
+ src/stataflow/compat/stata/did.py
14
+ src/stataflow/compat/stata/factor_variables.py
15
+ src/stataflow/compat/stata/glm.py
16
+ src/stataflow/compat/stata/hdfe.py
17
+ src/stataflow/compat/stata/iv.py
18
+ src/stataflow/compat/stata/linear.py
19
+ src/stataflow/compat/stata/rdrobust.py
20
+ src/stataflow/estimators/__init__.py
21
+ src/stataflow/estimators/absorbing_ols.py
22
+ src/stataflow/estimators/csdid.py
23
+ src/stataflow/estimators/did_imputation.py
24
+ src/stataflow/estimators/eventstudyinteract.py
25
+ src/stataflow/estimators/fe.py
26
+ src/stataflow/estimators/glm.py
27
+ src/stataflow/estimators/iv.py
28
+ src/stataflow/estimators/ols.py
29
+ src/stataflow/estimators/ppmlhdfe.py
30
+ src/stataflow/estimators/rdrobust.py
31
+ src/stataflow/results/__init__.py
32
+ src/stataflow/results/result.py
33
+ src/stataflow/stata_runner/__init__.py
34
+ src/stataflow/stata_runner/runner.py
35
+ tests/test_compat_stata_did.py
36
+ tests/test_compat_stata_glm.py
37
+ tests/test_compat_stata_hdfe.py
38
+ tests/test_compat_stata_iv.py
39
+ tests/test_compat_stata_linear.py
40
+ tests/test_factor_variables.py
41
+ tests/test_hdfe_synthetic.py
42
+ tests/test_ols_against_statsmodels.py
43
+ tests/test_rdrobust.py
44
+ tests/test_result_schema.py
45
+ tests/test_smoke.py
46
+ tests/test_stata_runner.py
47
+ tests/test_validation_summary.py
@@ -0,0 +1 @@
1
+ stataflow