stata-code 0.7.2__tar.gz → 0.8.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 (71) hide show
  1. {stata_code-0.7.2 → stata_code-0.8.0}/CHANGELOG.md +27 -1
  2. {stata_code-0.7.2 → stata_code-0.8.0}/PKG-INFO +56 -6
  3. {stata_code-0.7.2 → stata_code-0.8.0}/README.md +55 -5
  4. stata_code-0.8.0/docs/industry-leader-roadmap.md +99 -0
  5. stata_code-0.8.0/examples/06-cross-stack-parity-audit.md +101 -0
  6. stata_code-0.8.0/examples/07-data-mcp-handoff.md +77 -0
  7. {stata_code-0.7.2 → stata_code-0.8.0}/examples/README.md +2 -0
  8. {stata_code-0.7.2 → stata_code-0.8.0}/pyproject.toml +2 -1
  9. stata_code-0.8.0/scripts/check_github_actions.py +96 -0
  10. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/__init__.py +1 -1
  11. stata_code-0.8.0/stata_code/__main__.py +6 -0
  12. stata_code-0.8.0/stata_code/cli.py +73 -0
  13. stata_code-0.8.0/stata_code/doctor.py +285 -0
  14. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/mcp/server.py +458 -1
  15. stata_code-0.8.0/tests/test_doctor.py +148 -0
  16. stata_code-0.8.0/tests/test_github_actions.py +52 -0
  17. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_mcp.py +133 -0
  18. stata_code-0.8.0/tests/test_method_prompts.py +167 -0
  19. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_skill_package.py +10 -0
  20. {stata_code-0.7.2 → stata_code-0.8.0}/.gitignore +0 -0
  21. {stata_code-0.7.2 → stata_code-0.8.0}/LICENSE +0 -0
  22. {stata_code-0.7.2 → stata_code-0.8.0}/LICENSE-POLICY.md +0 -0
  23. {stata_code-0.7.2 → stata_code-0.8.0}/PUBLISHING.md +0 -0
  24. {stata_code-0.7.2 → stata_code-0.8.0}/SCHEMA.md +0 -0
  25. {stata_code-0.7.2 → stata_code-0.8.0}/docs/design/hard_timeout.md +0 -0
  26. {stata_code-0.7.2 → stata_code-0.8.0}/examples/01-basic-regression.md +0 -0
  27. {stata_code-0.7.2 → stata_code-0.8.0}/examples/02-did-card-krueger.md +0 -0
  28. {stata_code-0.7.2 → stata_code-0.8.0}/examples/03-graphs.md +0 -0
  29. {stata_code-0.7.2 → stata_code-0.8.0}/examples/04-multi-session.md +0 -0
  30. {stata_code-0.7.2 → stata_code-0.8.0}/examples/05-large-matrix.md +0 -0
  31. {stata_code-0.7.2 → stata_code-0.8.0}/schema/run_result.schema.json +0 -0
  32. {stata_code-0.7.2 → stata_code-0.8.0}/scripts/build_skill_zip.py +0 -0
  33. {stata_code-0.7.2 → stata_code-0.8.0}/scripts/check_versions.py +0 -0
  34. {stata_code-0.7.2 → stata_code-0.8.0}/scripts/export_schema.py +0 -0
  35. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/__init__.py +0 -0
  36. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/_pool.py +0 -0
  37. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/_refs.py +0 -0
  38. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/_runtime.py +0 -0
  39. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/errors.py +0 -0
  40. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/log_artifacts.py +0 -0
  41. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/notebook.py +0 -0
  42. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/run_index.py +0 -0
  43. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/runner.py +0 -0
  44. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/core/schema.py +0 -0
  45. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/__init__.py +0 -0
  46. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/__main__.py +0 -0
  47. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/assets/logo-32x32.png +0 -0
  48. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/assets/logo-64x64.png +0 -0
  49. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/assets/logo-svg.svg +0 -0
  50. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/kernel/kernel.py +0 -0
  51. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/mcp/__init__.py +0 -0
  52. {stata_code-0.7.2 → stata_code-0.8.0}/stata_code/mcp/__main__.py +0 -0
  53. {stata_code-0.7.2 → stata_code-0.8.0}/tests/__init__.py +0 -0
  54. {stata_code-0.7.2 → stata_code-0.8.0}/tests/conftest.py +0 -0
  55. {stata_code-0.7.2 → stata_code-0.8.0}/tests/fixtures/.gitkeep +0 -0
  56. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_cancel.py +0 -0
  57. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_errors.py +0 -0
  58. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_kernel.py +0 -0
  59. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_log_artifacts.py +0 -0
  60. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_mcp_stdio.py +0 -0
  61. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_new_tools.py +0 -0
  62. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_notebook.py +0 -0
  63. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_notebook_phase2.py +0 -0
  64. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_pool.py +0 -0
  65. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_public_api.py +0 -0
  66. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_release_versions.py +0 -0
  67. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_run_index.py +0 -0
  68. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_runner.py +0 -0
  69. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_runtime_discovery.py +0 -0
  70. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_schema.py +0 -0
  71. {stata_code-0.7.2 → stata_code-0.8.0}/tests/test_schema_artifact.py +0 -0
@@ -4,7 +4,33 @@ All notable changes to `stata-code` are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); the project adheres
5
5
  to semver-major.minor for the result schema (see `SCHEMA.md` §6).
6
6
 
7
- ## Unreleased
7
+ ## 0.8.0 — 2026-06-20
8
+
9
+ ### Added
10
+
11
+ - **Economist workflow coordination and roadmap.** Added
12
+ `AGENT_COORDINATION.md` for concurrent-agent lanes and
13
+ `docs/industry-leader-roadmap.md` for the one-month product plan: workflow
14
+ intelligence, parity audits, data-MCP handoff, editor/artifact polish, and
15
+ distribution diagnostics.
16
+ - **Cross-stack and data-MCP workflow references.** The `stata-code` skill now
17
+ includes `references/parity-audit.md` and
18
+ `references/data-mcp-handoff.md`, plus cookbook examples for cross-stack
19
+ parity audits and external-data-MCP handoff into Stata.
20
+ - **Modern empirical-economics package notes.** Added package references for
21
+ `csdid`, `drdid`, `did_imputation`, `eventstudyinteract`,
22
+ `did_multiplegt_dyn`, `rdrobust`, `ivreg2`, `ivreghdfe`, `boottest`, and
23
+ `outreg2`, and wired them into the skill routing table.
24
+ - **MCP prompt discoverability for economist workflows.** Added
25
+ `plan_cross_stack_parity_audit`, `data_mcp_to_stata_handoff`,
26
+ `did_event_study`, `iv_2sls`, `rdd`, `publication_table`, and
27
+ `cross_validate_did` prompts so clients can discover the new protocols and
28
+ turnkey empirical recipes directly through MCP.
29
+ - **Read-only installation diagnostics.** Added the top-level `stata-code`
30
+ console script with `doctor` / `verify` commands. The diagnostic reports
31
+ package/Python version, MCP and kernel extras, `pystata` discovery, console
32
+ scripts on `PATH`, client/VS Code hints, and an optional live Stata
33
+ version/edition probe without mutating user configuration.
8
34
 
9
35
  ## 0.7.2 — 2026-06-20
10
36
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stata-code
3
- Version: 0.7.2
3
+ Version: 0.8.0
4
4
  Summary: Agent-native Stata bridge — one core, multiple frontends (MCP, Jupyter, VSCode)
5
5
  Project-URL: Homepage, https://github.com/brycewang-stanford/stata-code
6
6
  Project-URL: Repository, https://github.com/brycewang-stanford/stata-code
@@ -67,6 +67,22 @@ Description-Content-Type: text/markdown
67
67
 
68
68
  `stata-code` lets you drive Stata from modern environments: an LLM agent (Claude Code, Cursor, Claude Desktop), a Jupyter notebook, or a VS Code editor session. All frontends share one Python core and return a stable, structured, **agent-friendly** result schema.
69
69
 
70
+ **For empirical economists.** Drive Stata in plain language: run **DiD, IV, RDD, and publication-ready `esttab` tables in one conversation** — then cross-check each estimate across Stata and Python so you only trust results that *agree* (the Cunningham cross-package robustness check).
71
+
72
+ **Try it in 60 seconds** with [Claude Code](https://github.com/anthropics/claude-code) — no global install needed:
73
+
74
+ ```bash
75
+ claude mcp add stata-code --scope user -- uvx --from "stata-code[mcp]" stata-code-mcp
76
+ ```
77
+
78
+ Then just ask:
79
+
80
+ > *"Using `data/cfps_panel.dta`, run a two-way fixed-effects regression of monthly wage on the treatment (controls: `age age2 edu industry`), then test heterogeneous effects with Callaway-Sant'Anna, and export an `esttab` table."*
81
+
82
+ `stata-code` writes the do-file, runs it, returns the table, and interprets the result — and can re-estimate the same ATT with [StatsPAI](https://github.com/brycewang-stanford/StatsPAI) to confirm the two stacks agree. These workflows ship as one-call MCP prompts (`did_event_study`, `iv_2sls`, `rdd`, `publication_table`, `cross_validate_did`) backed by an on-demand [recipe library](skills/stata-code/references/recipes/).
83
+
84
+ **Why `stata-code`:** MIT-licensed · ships as an MCP server, a bundled agent skill, a Jupyter kernel, **and** a VS Code extension · one structured, token-economy result schema (typed errors, native `r()` / `e()`) · cross-stack validation with StatsPAI for the Cunningham check.
85
+
70
86
  ```text
71
87
  ┌────────────────────────────────────────┐
72
88
  │ stata-code core (Python) │
@@ -84,12 +100,18 @@ Description-Content-Type: text/markdown
84
100
  └─────────────┘ └────────────┘ └─────────────────┘
85
101
  ```
86
102
 
87
- **Status: v0.7 (May 2026)** — the core, MCP server, Jupyter kernel, and VS Code extension work end-to-end against Stata 18 MP. The test suite covers schema, runner, MCP, kernel, notebook, run-index, subprocess-pool, and VS Code modules; CI also checks linting, type safety, schema generation, package metadata, and VSIX packaging. License: **MIT**.
103
+ **Status: v0.8 (June 2026)** — the core, MCP server, Jupyter kernel, and VS Code extension work end-to-end against Stata 18 MP. The test suite covers schema, runner, MCP, kernel, notebook, run-index, subprocess-pool, and VS Code modules; CI also checks linting, type safety, schema generation, package metadata, and VSIX packaging. License: **MIT**.
88
104
 
89
- Two workflows the current release explicitly supports for end users:
105
+ Three workflows the current tree explicitly supports for end users and agents:
90
106
 
91
107
  - **Run Stata code from a Jupyter notebook.** `pip install "stata-code[kernel]"` + `stata-code-kernel install --user` registers a **Stata** kernel that the Jupyter Notebook UI, JupyterLab, and the VS Code Jupyter extension all pick up by name. Cells render Stata logs, graphs, and warnings inline (the kernel logo bundled since v0.5 makes it appear in VS Code's kernel picker too). See [As a Jupyter Kernel](#as-a-jupyter-kernel).
92
108
  - **Optional agent "fix and rerun" loop.** `stata_run` returns typed `error.kind/line/context` plus `suggestions` on every failure. By default Claude Code only reports diagnostics — but if you explicitly say "fix this and rerun until it passes", the agent uses the same fields to edit your `.do` file and re-call `stata_run` until the run is green. The repair loop is **opt-in**: failed runs are diagnostics first, not automatic rewrite permission. See [Error Recovery in Agent Workflows](#error-recovery-in-agent-workflows).
109
+ - **Economist workflow guides.** The bundled skill and cookbook now cover
110
+ modern DiD, IV/weak-IV, RDD, table export, data-MCP handoff, and
111
+ cross-stack parity audits. `stata-code` runs and audits the Stata leg; R,
112
+ Python, and official data MCPs remain separate tools with explicit handoff
113
+ files and source metadata. See [`skills/stata-code/references/`](skills/stata-code/references/)
114
+ and [`examples/`](examples/).
93
115
 
94
116
  ---
95
117
 
@@ -138,6 +160,19 @@ pip install -e ".[mcp,kernel]"
138
160
 
139
161
  Note: `pystata` is **not** on PyPI; it ships with Stata. `stata-code` auto-discovers it on macOS at `/Applications/Stata/utilities/pystata` and at equivalent Linux / Windows paths. If your install is elsewhere, add it to `PYTHONPATH` before importing.
140
162
 
163
+ Verify the local setup with the read-only doctor:
164
+
165
+ ```bash
166
+ stata-code doctor
167
+ stata-code doctor --json # machine-readable output
168
+ stata-code doctor --no-stata-probe # skip live Stata initialization
169
+ ```
170
+
171
+ The doctor reports the package/Python version, MCP and Jupyter extras, `pystata`
172
+ discovery, console scripts on `PATH`, client/VS Code configuration hints, and a
173
+ best-effort Stata version/edition probe. It never edits shell, Stata, Claude, or
174
+ VS Code config.
175
+
141
176
  ---
142
177
 
143
178
  ## Quick Start
@@ -315,8 +350,11 @@ resources:
315
350
 
316
351
  MCP prompts are available for common agent workflows:
317
352
  `run_do_file_and_report`, `debug_stata_error`,
318
- `fix_and_rerun_until_passes`, `replication_audit`, and
319
- `summarize_estimation_results`.
353
+ `fix_and_rerun_until_passes`, `replication_audit`,
354
+ `plan_cross_stack_parity_audit`, `data_mcp_to_stata_handoff`,
355
+ `summarize_estimation_results`, `run_notebook_cell_and_report`,
356
+ `fix_and_rerun_notebook_cell`, `did_event_study`, `iv_2sls`, `rdd`,
357
+ `publication_table`, and `cross_validate_did`.
320
358
 
321
359
  ### As a Jupyter Kernel
322
360
 
@@ -358,6 +396,12 @@ Or open the **Extensions** sidebar in VS Code and search `stata-code`. The exten
358
396
 
359
397
  On first activation the extension probes for `stata-code-mcp` on `PATH` (and in any workspace `.venv` / `venv`). If nothing resolves, it shows a one-time install hint with the exact `pip install "stata-code[mcp]"` command — choose **Don't show again** to silence it for the installed extension version.
360
398
 
399
+ If the extension or an MCP client cannot find the server, run
400
+ `stata-code doctor --no-stata-probe` in the same Python environment. It reports
401
+ whether `stata-code-mcp` is on `PATH` and suggests absolute-path or
402
+ `python -m stata_code.mcp` fallbacks for GUI clients whose `PATH` differs from
403
+ your shell.
404
+
361
405
  #### Cell and section conventions
362
406
 
363
407
  The extension recognizes two complementary structural markers inside `.do` files. Either can be mixed in the same file; they do not conflict.
@@ -447,7 +491,7 @@ stata_code/
447
491
 
448
492
  ## Roadmap
449
493
 
450
- ### Done (through v0.7 — May 2026)
494
+ ### Done (current tree)
451
495
 
452
496
  - v1.0 result schema ([SCHEMA.md](SCHEMA.md))
453
497
  - `pystata`-based runner with native-typed `r()`, `e()`, and matrices
@@ -463,6 +507,12 @@ stata_code/
463
507
  - Subprocess-backed hard timeout and cancellation for the public Python API and MCP server: `timeout_ms`, `cancel(session_id)`, and MCP `cancel_session`
464
508
  - Per-cell repair loop on `.ipynb` via `notebook_outline` / `notebook_get_cell` / `notebook_edit_cell` with optimistic-concurrency `expected_source` guards and `origin_cell_id` echo on `RunResult`
465
509
  - Persistent run bundles + `list_runs` query over `manifest.json` files (filter by cell / origin / session / since / ok; page with limit / offset)
510
+ - Read-only `stata-code doctor` / `verify` diagnostics for package version,
511
+ extras, `pystata` discovery, console scripts, client hints, and optional live
512
+ Stata version probing
513
+ - Economist workflow layer: skill references and examples for modern DiD,
514
+ IV/weak-IV, RDD, table export, data-MCP handoff, and cross-stack parity
515
+ audits
466
516
  - JSON Schema artifact auto-generated from `schema.py`: [`schema/run_result.schema.json`](schema/run_result.schema.json)
467
517
  - VS Code extension published to the Marketplace as [`brycewang-stanford.stata-code-vscode`](https://marketplace.visualstudio.com/items?itemName=brycewang-stanford.stata-code-vscode): syntax highlighting, section outline/navigation, code-lens cell and section runners, sidebar (sessions / last result / run history / logs / graphs), status bar, completions, conservative variable rename, diagnostics, MCP child-process spawn
468
518
  - Clean-room license policy ([LICENSE-POLICY.md](LICENSE-POLICY.md))
@@ -28,6 +28,22 @@
28
28
 
29
29
  `stata-code` lets you drive Stata from modern environments: an LLM agent (Claude Code, Cursor, Claude Desktop), a Jupyter notebook, or a VS Code editor session. All frontends share one Python core and return a stable, structured, **agent-friendly** result schema.
30
30
 
31
+ **For empirical economists.** Drive Stata in plain language: run **DiD, IV, RDD, and publication-ready `esttab` tables in one conversation** — then cross-check each estimate across Stata and Python so you only trust results that *agree* (the Cunningham cross-package robustness check).
32
+
33
+ **Try it in 60 seconds** with [Claude Code](https://github.com/anthropics/claude-code) — no global install needed:
34
+
35
+ ```bash
36
+ claude mcp add stata-code --scope user -- uvx --from "stata-code[mcp]" stata-code-mcp
37
+ ```
38
+
39
+ Then just ask:
40
+
41
+ > *"Using `data/cfps_panel.dta`, run a two-way fixed-effects regression of monthly wage on the treatment (controls: `age age2 edu industry`), then test heterogeneous effects with Callaway-Sant'Anna, and export an `esttab` table."*
42
+
43
+ `stata-code` writes the do-file, runs it, returns the table, and interprets the result — and can re-estimate the same ATT with [StatsPAI](https://github.com/brycewang-stanford/StatsPAI) to confirm the two stacks agree. These workflows ship as one-call MCP prompts (`did_event_study`, `iv_2sls`, `rdd`, `publication_table`, `cross_validate_did`) backed by an on-demand [recipe library](skills/stata-code/references/recipes/).
44
+
45
+ **Why `stata-code`:** MIT-licensed · ships as an MCP server, a bundled agent skill, a Jupyter kernel, **and** a VS Code extension · one structured, token-economy result schema (typed errors, native `r()` / `e()`) · cross-stack validation with StatsPAI for the Cunningham check.
46
+
31
47
  ```text
32
48
  ┌────────────────────────────────────────┐
33
49
  │ stata-code core (Python) │
@@ -45,12 +61,18 @@
45
61
  └─────────────┘ └────────────┘ └─────────────────┘
46
62
  ```
47
63
 
48
- **Status: v0.7 (May 2026)** — the core, MCP server, Jupyter kernel, and VS Code extension work end-to-end against Stata 18 MP. The test suite covers schema, runner, MCP, kernel, notebook, run-index, subprocess-pool, and VS Code modules; CI also checks linting, type safety, schema generation, package metadata, and VSIX packaging. License: **MIT**.
64
+ **Status: v0.8 (June 2026)** — the core, MCP server, Jupyter kernel, and VS Code extension work end-to-end against Stata 18 MP. The test suite covers schema, runner, MCP, kernel, notebook, run-index, subprocess-pool, and VS Code modules; CI also checks linting, type safety, schema generation, package metadata, and VSIX packaging. License: **MIT**.
49
65
 
50
- Two workflows the current release explicitly supports for end users:
66
+ Three workflows the current tree explicitly supports for end users and agents:
51
67
 
52
68
  - **Run Stata code from a Jupyter notebook.** `pip install "stata-code[kernel]"` + `stata-code-kernel install --user` registers a **Stata** kernel that the Jupyter Notebook UI, JupyterLab, and the VS Code Jupyter extension all pick up by name. Cells render Stata logs, graphs, and warnings inline (the kernel logo bundled since v0.5 makes it appear in VS Code's kernel picker too). See [As a Jupyter Kernel](#as-a-jupyter-kernel).
53
69
  - **Optional agent "fix and rerun" loop.** `stata_run` returns typed `error.kind/line/context` plus `suggestions` on every failure. By default Claude Code only reports diagnostics — but if you explicitly say "fix this and rerun until it passes", the agent uses the same fields to edit your `.do` file and re-call `stata_run` until the run is green. The repair loop is **opt-in**: failed runs are diagnostics first, not automatic rewrite permission. See [Error Recovery in Agent Workflows](#error-recovery-in-agent-workflows).
70
+ - **Economist workflow guides.** The bundled skill and cookbook now cover
71
+ modern DiD, IV/weak-IV, RDD, table export, data-MCP handoff, and
72
+ cross-stack parity audits. `stata-code` runs and audits the Stata leg; R,
73
+ Python, and official data MCPs remain separate tools with explicit handoff
74
+ files and source metadata. See [`skills/stata-code/references/`](skills/stata-code/references/)
75
+ and [`examples/`](examples/).
54
76
 
55
77
  ---
56
78
 
@@ -99,6 +121,19 @@ pip install -e ".[mcp,kernel]"
99
121
 
100
122
  Note: `pystata` is **not** on PyPI; it ships with Stata. `stata-code` auto-discovers it on macOS at `/Applications/Stata/utilities/pystata` and at equivalent Linux / Windows paths. If your install is elsewhere, add it to `PYTHONPATH` before importing.
101
123
 
124
+ Verify the local setup with the read-only doctor:
125
+
126
+ ```bash
127
+ stata-code doctor
128
+ stata-code doctor --json # machine-readable output
129
+ stata-code doctor --no-stata-probe # skip live Stata initialization
130
+ ```
131
+
132
+ The doctor reports the package/Python version, MCP and Jupyter extras, `pystata`
133
+ discovery, console scripts on `PATH`, client/VS Code configuration hints, and a
134
+ best-effort Stata version/edition probe. It never edits shell, Stata, Claude, or
135
+ VS Code config.
136
+
102
137
  ---
103
138
 
104
139
  ## Quick Start
@@ -276,8 +311,11 @@ resources:
276
311
 
277
312
  MCP prompts are available for common agent workflows:
278
313
  `run_do_file_and_report`, `debug_stata_error`,
279
- `fix_and_rerun_until_passes`, `replication_audit`, and
280
- `summarize_estimation_results`.
314
+ `fix_and_rerun_until_passes`, `replication_audit`,
315
+ `plan_cross_stack_parity_audit`, `data_mcp_to_stata_handoff`,
316
+ `summarize_estimation_results`, `run_notebook_cell_and_report`,
317
+ `fix_and_rerun_notebook_cell`, `did_event_study`, `iv_2sls`, `rdd`,
318
+ `publication_table`, and `cross_validate_did`.
281
319
 
282
320
  ### As a Jupyter Kernel
283
321
 
@@ -319,6 +357,12 @@ Or open the **Extensions** sidebar in VS Code and search `stata-code`. The exten
319
357
 
320
358
  On first activation the extension probes for `stata-code-mcp` on `PATH` (and in any workspace `.venv` / `venv`). If nothing resolves, it shows a one-time install hint with the exact `pip install "stata-code[mcp]"` command — choose **Don't show again** to silence it for the installed extension version.
321
359
 
360
+ If the extension or an MCP client cannot find the server, run
361
+ `stata-code doctor --no-stata-probe` in the same Python environment. It reports
362
+ whether `stata-code-mcp` is on `PATH` and suggests absolute-path or
363
+ `python -m stata_code.mcp` fallbacks for GUI clients whose `PATH` differs from
364
+ your shell.
365
+
322
366
  #### Cell and section conventions
323
367
 
324
368
  The extension recognizes two complementary structural markers inside `.do` files. Either can be mixed in the same file; they do not conflict.
@@ -408,7 +452,7 @@ stata_code/
408
452
 
409
453
  ## Roadmap
410
454
 
411
- ### Done (through v0.7 — May 2026)
455
+ ### Done (current tree)
412
456
 
413
457
  - v1.0 result schema ([SCHEMA.md](SCHEMA.md))
414
458
  - `pystata`-based runner with native-typed `r()`, `e()`, and matrices
@@ -424,6 +468,12 @@ stata_code/
424
468
  - Subprocess-backed hard timeout and cancellation for the public Python API and MCP server: `timeout_ms`, `cancel(session_id)`, and MCP `cancel_session`
425
469
  - Per-cell repair loop on `.ipynb` via `notebook_outline` / `notebook_get_cell` / `notebook_edit_cell` with optimistic-concurrency `expected_source` guards and `origin_cell_id` echo on `RunResult`
426
470
  - Persistent run bundles + `list_runs` query over `manifest.json` files (filter by cell / origin / session / since / ok; page with limit / offset)
471
+ - Read-only `stata-code doctor` / `verify` diagnostics for package version,
472
+ extras, `pystata` discovery, console scripts, client hints, and optional live
473
+ Stata version probing
474
+ - Economist workflow layer: skill references and examples for modern DiD,
475
+ IV/weak-IV, RDD, table export, data-MCP handoff, and cross-stack parity
476
+ audits
427
477
  - JSON Schema artifact auto-generated from `schema.py`: [`schema/run_result.schema.json`](schema/run_result.schema.json)
428
478
  - VS Code extension published to the Marketplace as [`brycewang-stanford.stata-code-vscode`](https://marketplace.visualstudio.com/items?itemName=brycewang-stanford.stata-code-vscode): syntax highlighting, section outline/navigation, code-lens cell and section runners, sidebar (sessions / last result / run history / logs / graphs), status bar, completions, conservative variable rename, diagnostics, MCP child-process spawn
429
479
  - Clean-room license policy ([LICENSE-POLICY.md](LICENSE-POLICY.md))
@@ -0,0 +1,99 @@
1
+ # stata-code Industry Leadership Roadmap
2
+
3
+ This roadmap translates the June 2026 empirical-research MCP landscape into
4
+ work that fits `stata-code`'s architecture. The project should win by being the
5
+ most reliable agent-native Stata execution and audit layer for empirical
6
+ economists, not by becoming a grab-bag data platform or a second R/Python
7
+ runtime.
8
+
9
+ ## North Star
10
+
11
+ `stata-code` should be the default way an AI agent runs, inspects, repairs, and
12
+ audits Stata work:
13
+
14
+ - one execution core across Python, MCP, Jupyter, and VS Code;
15
+ - stable `RunResult` schema with typed errors and native `r()` / `e()` values;
16
+ - token-efficient logs, graphs, matrices, and run bundles;
17
+ - economist-facing workflows for DiD, IV, RDD, tables, data handoff, and
18
+ cross-package verification.
19
+
20
+ ## Product Pillars
21
+
22
+ 1. **Reliable execution contract.** Keep `SCHEMA.md` load-bearing. Agents
23
+ branch on `ok`, `error.kind`, `results.e`, refs, and run manifests instead
24
+ of parsing log prose.
25
+ 2. **Econometrics workflow intelligence.** Ship concise skill references and
26
+ prompts that know the Stata commands economists actually use: `csdid`,
27
+ `did_imputation`, `eventstudyinteract`, `rdrobust`, `ivreg2`,
28
+ `ivreghdfe`, `boottest`, `esttab`, `collect`, and related packages.
29
+ 3. **Cross-stack parity audits.** Treat R/Python/Stata disagreement as a first
30
+ class research risk. `stata-code` should run the Stata leg and define the
31
+ comparison protocol without pretending to own the R or Python runtimes.
32
+ 4. **Data-MCP handoff.** External MCP servers can discover and fetch official
33
+ data. `stata-code` should document and validate the handoff into Stata:
34
+ source metadata, stable raw files, key checks, and reproducible imports.
35
+ 5. **Editor and artifact ergonomics.** VS Code should make sessions, graphs,
36
+ logs, tables, data previews, and run bundles easy to inspect without hiding
37
+ the underlying structured result.
38
+ 6. **Distribution confidence.** Install and runtime checks should be easy to
39
+ verify without mutating user config. Prefer `doctor`/`verify` diagnostics
40
+ before any automatic config writer.
41
+
42
+ ## Scope Boundaries
43
+
44
+ `stata-code` should not directly bundle data-provider APIs, R sessions, Python
45
+ causal libraries, or paid services. Those are separate tools. The durable
46
+ boundary is: external data/model tools produce files or results; `stata-code`
47
+ executes and audits the Stata side with traceable artifacts.
48
+
49
+ ## One-Month Execution Plan
50
+
51
+ ### Week 1: Workflow Layer
52
+
53
+ - Add cross-agent coordination and this roadmap.
54
+ - Expand the skill reference library for modern DiD, IV/weak-IV, RDD,
55
+ table-export, data-MCP handoff, and parity audits.
56
+ - Add examples that show how agents should use the workflows without claiming
57
+ unsupported automation.
58
+ - Add MCP prompts for parity audit planning, data-MCP-to-Stata handoff, and
59
+ turnkey method templates for DiD/event study, IV/2SLS, RDD, and publication
60
+ tables.
61
+ - Validate with skill packaging tests, MCP prompt tests, and markdown hygiene.
62
+
63
+ ### Week 2: Diagnostics and Setup Confidence
64
+
65
+ - Ship a read-only `stata-code doctor` / `verify` command that reports Python,
66
+ `stata-code`, MCP extras, `pystata` discovery, Stata version/edition, PATH
67
+ resolution, and common client config hints.
68
+ - Keep config writing out of scope until backups and dry-run behavior exist.
69
+ - Add tests for missing `pystata`, missing MCP extra, path mismatch, and JSON
70
+ output.
71
+
72
+ ### Week 3: VS Code and Artifacts
73
+
74
+ - Improve dataset preview from first-100 text output toward a paged/filterable
75
+ view or a clearly documented intermediate step.
76
+ - Surface table/export artifacts from run bundles more explicitly.
77
+ - Add tests around formatter and tree-provider behavior before broad UI work.
78
+
79
+ ### Week 4: Release Quality
80
+
81
+ - Sweep README.md, README.zh.md, vscode/README.md, CHANGELOG.md, examples,
82
+ and skill docs for drift.
83
+ - Run release-relevant checks: version guard, schema export, skill zip build,
84
+ MCP tests, core tests that do not require Stata, and VS Code compile/tests if
85
+ touched.
86
+ - Prepare release notes that separate shipped features from roadmap items.
87
+
88
+ ## Success Criteria
89
+
90
+ - Agents can find a documented path for the top empirical workflows without
91
+ loading the whole reference library.
92
+ - Parity audits preserve sample definitions, package versions, estimator
93
+ defaults, failure/refusal behavior, and numeric tolerances.
94
+ - Data pulled by external MCP servers enters Stata through a reproducible raw
95
+ file plus metadata handoff, not through unstated browser-copy steps.
96
+ - User-facing docs explain that `stata-code` runs Stata and coordinates with
97
+ other MCP tools; they do not imply that it directly runs R/Python or hosts
98
+ official data APIs.
99
+ - All changed surfaces have targeted validation evidence before handoff.
@@ -0,0 +1,101 @@
1
+ # 06 — Cross-stack parity audit
2
+
3
+ > **Goal:** show how an agent should use `stata-code` for the Stata leg of a
4
+ > Stata/R/Python robustness audit without pretending that one tool owns every
5
+ > runtime.
6
+
7
+ This example is intentionally protocol-first. The exact R/Python calls depend
8
+ on which external MCP servers or local runtimes the user has installed. The
9
+ Stata leg is concrete and traceable through `stata_run`.
10
+
11
+ ## Step 1: freeze the common sample
12
+
13
+ **Agent calls:**
14
+
15
+ ```json
16
+ {
17
+ "tool": "stata_run",
18
+ "arguments": {
19
+ "code": "use data/panel.dta, clear\negen unit_id = group(firm_id), label\negen time_id = group(year), label\ngen byte audit_sample = !missing(y, first_treat, unit_id, time_id, x1, x2)\nkeep if audit_sample\nisid unit_id time_id\ncompress\ndatasignature set, reset\nsave data/derived/parity_sample.dta, replace\nexport delimited using data/derived/parity_sample.csv, replace",
20
+ "origin_path": "/abs/project/analysis/00_freeze_parity_sample.do",
21
+ "origin_kind": "file",
22
+ "persist_log_files": true
23
+ }
24
+ }
25
+ ```
26
+
27
+ **Agent reads:**
28
+
29
+ - `ok`, `rc`, and any typed error.
30
+ - `dataset.n_obs` and `dataset.n_vars`.
31
+ - `log.files.directory` for the run bundle.
32
+ - generated files copied into `outputs/` when persistence is enabled.
33
+
34
+ The CSV is the handoff file for R/Python tools. The DTA is the Stata source for
35
+ the Stata estimators. Do not let every package define its own missing-value
36
+ sample.
37
+
38
+ ## Step 2: run the Stata estimator
39
+
40
+ **Agent calls:**
41
+
42
+ ```json
43
+ {
44
+ "tool": "stata_run",
45
+ "arguments": {
46
+ "code": "use data/derived/parity_sample.dta, clear\ncsdid y x1 x2, ivar(unit_id) time(time_id) gvar(first_treat) method(dripw)\nestat simple\nestat event\ncsdid_plot",
47
+ "session_id": "stata_csdid",
48
+ "origin_path": "/abs/project/analysis/01_stata_csdid.do",
49
+ "origin_kind": "file",
50
+ "persist_log_files": true
51
+ }
52
+ }
53
+ ```
54
+
55
+ **Agent reads:**
56
+
57
+ - `results.e.scalars` for `N` and available fit/ATT scalars.
58
+ - `results.e.matrices` for coefficient and VCE payloads.
59
+ - `graphs[0].ref` for the event-study plot.
60
+ - `warnings` and `log.error_window` for dropped cohorts or estimator refusal.
61
+
62
+ If `csdid` is missing, the repair loop may call:
63
+
64
+ ```json
65
+ {"tool": "install_package", "arguments": {"name": "csdid"}}
66
+ ```
67
+
68
+ and, if needed:
69
+
70
+ ```json
71
+ {"tool": "install_package", "arguments": {"name": "drdid"}}
72
+ ```
73
+
74
+ ## Step 3: run external legs with their own tools
75
+
76
+ The agent should hand `data/derived/parity_sample.csv` plus the written parity
77
+ contract to the R/Python tools that are actually available. `stata-code` should
78
+ not claim those estimates. It should record their package versions, options,
79
+ sample `N`, warnings/refusals, and output files in the comparison table.
80
+
81
+ ## Step 4: compare only like with like
82
+
83
+ | Stack | Package | Target | N | Estimate | SE | Warning/refusal |
84
+ | --- | --- | --- | ---: | ---: | ---: | --- |
85
+ | Stata | `csdid` | overall ATT from `estat simple` | from `results.e` | from `e(b)`/scalar | from `e(V)` | from `warnings` |
86
+ | R | external | same target | external | external | external | external |
87
+ | Python | external | same target | external | external | external | external |
88
+
89
+ Do not compare an overall ATT to an event-time coefficient. Do not hide package
90
+ refusals. If sample `N` differs, stop and fix the sample before interpreting
91
+ coefficient differences.
92
+
93
+ ## Step 5: report conservatively
94
+
95
+ Use language like:
96
+
97
+ - "The Stata `csdid` leg ran on the frozen sample and produced ..."
98
+ - "The R/Python legs were run by external tools; stata-code only coordinated the
99
+ handoff and Stata audit trail."
100
+ - "The estimates agree within the predeclared tolerance" or "they diverge, with
101
+ the likely source being sample/default/failure differences."
@@ -0,0 +1,77 @@
1
+ # 07 — Data-MCP handoff into Stata
2
+
3
+ > **Goal:** show how an agent should turn data fetched by an external data MCP
4
+ > into a reproducible Stata analysis.
5
+
6
+ Use this pattern for OpenEcon, World Bank Data360, FRED, OECD, IMF, Eurostat, or
7
+ project-specific database MCPs. The data MCP discovers and fetches data;
8
+ `stata-code` imports, validates, analyzes, and records the Stata run.
9
+
10
+ ## Step 1: persist the external data pull
11
+
12
+ The external data MCP should save:
13
+
14
+ ```text
15
+ data/raw/oecd_youth_unemployment_pisa_2010_2023.csv
16
+ data/raw/oecd_youth_unemployment_pisa_2010_2023.source.json
17
+ ```
18
+
19
+ The metadata file should include provider, endpoint or source URL, indicator
20
+ IDs, countries, date range, fetch timestamp, units, and any non-Stata
21
+ transformations.
22
+
23
+ ## Step 2: import and validate through Stata
24
+
25
+ **Agent calls:**
26
+
27
+ ```json
28
+ {
29
+ "tool": "stata_run",
30
+ "arguments": {
31
+ "code": "version 18\nclear all\nset more off\nlocal raw \"data/raw/oecd_youth_unemployment_pisa_2010_2023.csv\"\nlocal out \"data/derived/oecd_youth_unemployment_pisa_2010_2023.dta\"\ncapture confirm file \"`raw'\"\nif _rc {\n display as error \"Missing raw data file: `raw'\"\n exit 601\n}\nimport delimited using \"`raw'\", varnames(1) clear bindquote(strict) encoding(UTF-8)\ncompress\nisid country year\nassert inrange(year, 2010, 2023)\nassert !missing(country, year)\nnotes _dta: Source metadata stored next to raw CSV.\ndatasignature set, reset\nsave \"`out'\", replace",
32
+ "origin_path": "/abs/project/analysis/00_import_oecd.do",
33
+ "origin_kind": "file",
34
+ "persist_log_files": true
35
+ }
36
+ }
37
+ ```
38
+
39
+ **Agent reads:**
40
+
41
+ - `ok` and `error.kind` if import/validation failed.
42
+ - `dataset.n_obs`, `dataset.n_vars`, and variables.
43
+ - run-bundle paths for logs and generated `.dta`.
44
+
45
+ ## Step 3: analyze the derived DTA
46
+
47
+ **Agent calls:**
48
+
49
+ ```json
50
+ {
51
+ "tool": "stata_run",
52
+ "arguments": {
53
+ "code": "use data/derived/oecd_youth_unemployment_pisa_2010_2023.dta, clear\nsummarize youth_unemployment pisa_math\npwcorr youth_unemployment pisa_math, sig obs\ntwoway scatter pisa_math youth_unemployment, xtitle(\"Youth unemployment rate\") ytitle(\"PISA math score\") title(\"OECD countries, 2010-2023\")",
54
+ "origin_path": "/abs/project/analysis/01_scatter_corr.do",
55
+ "origin_kind": "file",
56
+ "persist_log_files": true
57
+ }
58
+ }
59
+ ```
60
+
61
+ **Agent reads:**
62
+
63
+ - `results.r.scalars` for correlation/post-command scalars when available.
64
+ - `graphs[0].ref` for the scatter plot.
65
+ - `log.ref` only if the structured fields do not contain the needed detail.
66
+
67
+ ## Step 4: report provenance
68
+
69
+ The final answer should cite the metadata file and Stata run bundle, not the
70
+ LLM's memory. A good handoff report includes:
71
+
72
+ - source provider and indicator IDs;
73
+ - raw and derived file paths;
74
+ - import validation checks;
75
+ - Stata commands run;
76
+ - graph/table/log artifact paths;
77
+ - any missingness, unit, or key warnings.
@@ -11,5 +11,7 @@ The recurring theme is **token economy**: by default the server returns a 20-lin
11
11
  | 03 | [Graphs](./03-graphs.md) | `graph://` refs vs. inline base64; `include_graphs="inline"` opt-in |
12
12
  | 04 | [Multi-session](./04-multi-session.md) | Two parallel analyses via `session_id` (Stata frames under the hood) |
13
13
  | 05 | [Large matrices](./05-large-matrix.md) | `matrix://` refs when a result exceeds the 10,000-cell inline cap |
14
+ | 06 | [Cross-stack parity audit](./06-cross-stack-parity-audit.md) | Freeze one sample, run the Stata leg, and compare against external R/Python legs without hiding package disagreement |
15
+ | 07 | [Data-MCP handoff](./07-data-mcp-handoff.md) | Persist external data-MCP pulls, import/validate them in Stata, and keep provenance in run bundles |
14
16
 
15
17
  Every Stata command shown is real syntax. Tool names, argument names, and response field names match `stata_code/mcp/server.py` and `SCHEMA.md` v1.0. Where a JSON response is abbreviated for readability, an inline comment marks what was cut.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "stata-code"
7
- version = "0.7.2"
7
+ version = "0.8.0"
8
8
  description = "Agent-native Stata bridge — one core, multiple frontends (MCP, Jupyter, VSCode)"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -47,6 +47,7 @@ kernel = ["ipykernel>=6.0"]
47
47
  all = ["stata-code[mcp,kernel]"]
48
48
 
49
49
  [project.scripts]
50
+ stata-code = "stata_code.cli:run_main"
50
51
  stata-code-kernel = "stata_code.kernel.kernel:run_main"
51
52
  stata-code-mcp = "stata_code.mcp.server:run_main"
52
53