Stata Econ MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Stata Econ MCP Run a panel fixed effects regression of wage on education with firm-clustered SEs"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Stata Econ MCP
English | 简体中文
Let Claude (Claude Desktop chat or Claude Code) drive your own local Stata to run regressions.
Uses the official pystata engine that ships with Stata (
<Stata install dir>/utilities/pystata), so it runs your own Stata, license, and installed community packages (reghdfe, csdid, ...).Stata runs in a separate worker process with a persistent session: data,
estimates storeresults and locals survive between calls. If Stata hangs,stata_restartkills and restarts it.Ships with an applied-econometrics playbook (panel FE, DiD, staggered DiD, DDD, event studies, LaTeX tables, referee standards) that Claude reads through
stata_guide.
Requirements
Stata 17 or later (MP / SE / BE), installed and licensed on the same machine
uv (or Python 3.11+)
Tested on macOS (Apple Silicon) with Stata 18 MP. Linux and Windows should work in principle but are untested; set
STATA_DIRthere.
Related MCP server: io.github.aliveranme/stata-mcp
Installation
git clone https://github.com/shanyuzhang/stata-econ-mcp.git
cd stata-econ-mcp
uv syncThe server executable is <repo path>/.venv/bin/stata-econ-mcp (called <SERVER> below; use the absolute path).
Claude Code
claude mcp add stata --scope user -- "<SERVER>"Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json
(Windows: %APPDATA%\Claude\claude_desktop_config.json) and add under mcpServers:
{
"mcpServers": {
"stata": {
"command": "<SERVER>",
"args": []
}
}
}Save, then fully quit and reopen Claude Desktop.
If Stata is not in a default location (on macOS the server searches /Applications/Stata,
/Applications/StataNow, ...), add environment variables to the entry:
"env": { "STATA_DIR": "/path/to/Stata", "STATA_EDITION": "mp" }Tools
Tool | Purpose |
| Run a block of Stata code (quick checks) |
| Save code as a do-file and run it with a log (for real analysis) |
| Keep waiting for a long job / restart Stata |
| Inspect data: overview, describe, summarize, xtdescribe, missing values, ... |
| Structured coefficients, SEs, p-values, N, clusters, FE |
| Publication LaTeX regression tables (esttab, booktabs) |
| Export graphs (PNG shown in chat + PDF for LaTeX) |
| Read help files of official and community commands |
| The econometrics playbook |
| Status and installed-package check / switch project folder |
Where outputs go
<project folder>/stata_output/{do,logs,tables,figures}
Claude Code (or the Code tab in Claude Desktop): the project folder is the session's folder.
Claude Desktop chat (no folder): defaults to
~/Documents/StataMCP/. You can also tell Claude "put the project in " and it will callstata_set_workdir.Every command is appended to
logs/history_<date>.dofor reproducibility.
Environment variables (optional)
Variable | Default |
| auto-detected |
| inferred from the install (mp / se / be) |
| auto (session folder, then the default folder) |
|
|
|
|
|
|
Recommended community packages
ssc install reghdfe
ssc install ftools
ssc install estout
ssc install coefplot
ssc install csdid
ssc install drdid
ssc install did_imputation
ssc install eventstudyinteract
ssc install event_plot
ssc install bootteststata_status lists which ones are installed.
Known issues
If your
profile.docontains GUI-only commands (such aswindow menu), it stops early in headless mode. The server re-appliesmore off,type double,maxvarandlinesizeafter startup.Stata's embedded Python bridge cannot handle interpreter paths that contain spaces. If the repo lives in such a folder, the worker creates a space-free symlink (
~/.cache/stata-econ-mcp/python) automatically.The safety rules (no
shell/!, no deleting user files, ask before installing packages) are instructions to Claude, not enforced in code. The server runs your full local Stata, so only use it with clients you trust.
License
MIT
Available Tools
12 toolsstata_dataB
Inspect the dataset in memory.
action: overview | describe | summarize | detail (summarize, detail) | codebook | list |
tabulate | xtdescribe | missing | count
varlist: optional Stata varlist; condition: optional Stata if expression (without the word if);
n: rows for list.
Inputs: n, action, varlist, condition. Returns: result
stata_doB
Save code as a do-file (if given) and execute it with a text log.
filename: e.g. "01_clean" or "analysis/did_main.do". A bare name goes to stata_output/do/;
a relative path with folders is relative to the working directory; absolute paths are allowed.
If code is omitted, the existing do-file is run. Log is written to stata_output/logs/.log.
Inputs: filename (required), code, wait_seconds. Returns: result
stata_graphA
Export the current (or named) Stata graph to stata_output/figures and display it.
Draw the graph first with stata_run/stata_do (e.g. coefplot, twoway, event-study plots). Saves .png (shown inline) and, if pdf=True, .pdf for LaTeX.
Inputs: filename (required), pdf, width, graph_name.
stata_guideA
Applied-econometrics playbook written for this server. Read before modelling.
topics: index, workflow, panel_fe, did, ddd, event_study, latex_tables, econ_standards, stata_gotchas
Inputs: topic. Returns: result
stata_helpA
Read the official Stata help file for a command (also works for installed packages, e.g. reghdfe, csdid).
Inputs: command (required), max_chars. Returns: result
stata_restartA
Kill and restart the Stata session (clears data in memory). Use if Stata hangs.
Inputs: no named parameters. Returns: result
stata_resultsB
Structured coefficients and statistics of the active (or a stored) estimation.
name: optional estimates store name; if given it is restored first.
Returns a coefficient table (b, se, t/z, p, CI) plus e() scalars and key macros (cmd, depvar,
vce, clustvar, absvars...). Use this to read results precisely instead of parsing text output.
Inputs: name, include_base. Returns: result
stata_runA
Run Stata code in the persistent session and return the output.
code may be multi-line (supports ///, comments, locals within the block).
Use for quick checks/exploration. For real analysis prefer stata_do (saved do-file + log).
If the job exceeds wait_seconds it keeps running; then call stata_wait.
Inputs: code (required), wait_seconds. Returns: result
stata_set_workdirA
Set the project folder. Outputs then go to /stata_output and Stata cds there.
Use when the user names a project folder, or if the detected folder is wrong.
Inputs: path (required). Returns: result
stata_statusA
Show Stata install, working/output folders, and which key econometrics packages are installed.
Inputs: no named parameters. Returns: result
stata_tableA
Export stored models to a publication LaTeX table (esttab, booktabs) and return the .tex.
models: names from estimates store (e.g. ["m1","m2","m3"]), in column order.
filename: bare name -> stata_output/tables/.tex.
keep/order: Stata coefficient lists, e.g. "treat_post" or "1.treat#1.post".
coeflabels: {"treat_post": "Treat $\times$ Post"}; fe_rows: {"Firm FE": ["Yes","Yes","Yes"], ...}
stats: from N, r2, r2_a, r2_within, N_clust, F, ymean (ymean must be added via estadd);
default ["N","r2_a"] (use r2_within for reghdfe).
se_note: describe the SEs, e.g. "Standard errors clustered at the county level in parentheses."
Stars: * p<0.10, ** p<0.05, *** p<0.01. Requires estout (ssc install estout).
Inputs: models (required), filename (required), keep, label, +11 more. Returns: result
stata_waitB
Keep waiting for a long-running Stata job started earlier and return its output.
Inputs: wait_seconds. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 12 tools
Most tools target clearly distinct facets of the Stata workflow (run, wait, restart, workdir, status, data, results, graph, table, help, guide). The main risk is stata_run vs stata_do, which both execute code, but the descriptions explicitly differentiate quick exploration from saved do-files with logs, and stata_help vs stata_guide are separated by 'official help file' vs 'econometrics playbook'.
All names share a uniform snake_case `stata_` prefix, making the set instantly recognizable. There is a minor stylistic split between verb-led names (stata_run, stata_do, stata_wait, stata_restart, stata_set_workdir) and noun-led names (stata_data, stata_results, stata_graph, stata_table), but it stays readable and predictable.
Twelve tools is a well-scoped set for a persistent-session Stata server: session control, execution, inspection, export, and reference docs. Each tool maps to a real step in an econometric workflow with no filler.
The surface covers the full lifecycle: start/run/wait/restart the session, set the project folder, inspect data, extract structured estimates, export figures and LaTeX tables, plus help and a playbook. Minor gaps exist around browsing or cleaning previously produced output files (figures/tables/logs) and non-destructive interrupt, but stata_run is a general escape hatch that mitigates most of these.
Related MCP Connectors
A statistical analyst in your AI chat: bring data and a question, get a citable, re-runnable report.
Use your Mac, Windows or Linux computer from ChatGPT, Claude or Codex: files, commands, documents.
Let ChatGPT and Claude work on your own computer: files, terminal, Word, Excel and PDF.
Amazon Ads, Seller Central, Brand Analytics and AMC data in Claude, ChatGPT and any MCP client
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceConnects AI agents to a local Stata installation, enabling execution of Stata code, data inspection, graph generation, and result verification through natural language interactions.647 PyPI92AGPL 3.0
- AlicenseNot gradedqualityCmaintenanceMCP server that enables Claude to directly drive Stata, providing a persistent session and 75 tools for data management, estimation, post-estimation, graphs, and export. It lets users perform full Stata analyses through natural language instructions.MIT
- AlicenseAqualityCmaintenanceEnables LLM/agent applications to execute Stata code, load and inspect data, obtain structured regression results and graphs, and manage background tasks through the Model Context Protocol.10MIT
- AlicenseAqualityNot gradedmaintenanceEnables AI agents to invoke a local Stata installation, including a Windows Stata build under Wine on Linux and macOS, for regression analysis, econometrics, paper replication, and empirical research with command guards, resource monitoring, and automatic log capture.42AGPL 3.0