Skip to main content
Glama

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 store results and locals survive between calls. If Stata hangs, stata_restart kills 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_DIR there.

Related MCP server: io.github.aliveranme/stata-mcp

Installation

git clone https://github.com/shanyuzhang/stata-econ-mcp.git
cd stata-econ-mcp
uv sync

The 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

stata_run

Run a block of Stata code (quick checks)

stata_do

Save code as a do-file and run it with a log (for real analysis)

stata_wait / stata_restart

Keep waiting for a long job / restart Stata

stata_data

Inspect data: overview, describe, summarize, xtdescribe, missing values, ...

stata_results

Structured coefficients, SEs, p-values, N, clusters, FE

stata_table

Publication LaTeX regression tables (esttab, booktabs)

stata_graph

Export graphs (PNG shown in chat + PDF for LaTeX)

stata_help

Read help files of official and community commands

stata_guide

The econometrics playbook

stata_status / stata_set_workdir

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 call stata_set_workdir.

  • Every command is appended to logs/history_<date>.do for reproducibility.

Environment variables (optional)

Variable

Default

STATA_DIR

auto-detected

STATA_EDITION

inferred from the install (mp / se / be)

STATA_MCP_WORKDIR

auto (session folder, then the default folder)

STATA_MCP_DEFAULT_DIR

~/Documents/StataMCP

STATA_MCP_OUTPUT_SUBDIR

stata_output

STATA_MCP_WAIT_SECONDS

240 (after this the job keeps running in the background; collect it with stata_wait)

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 boottest

stata_status lists which ones are installed.

Known issues

  • If your profile.do contains GUI-only commands (such as window menu), it stops early in headless mode. The server re-applies more off, type double, maxvar and linesize after 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 tools
stata_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

    A3.7/5.0

    Scored across 12 tools

    Disambiguation4/5

    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'.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Connects AI agents to a local Stata installation, enabling execution of Stata code, data inspection, graph generation, and result verification through natural language interactions.
      647 PyPI
      92
      AGPL 3.0
    • A
      license
      A
      quality
      C
      maintenance
      Enables 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.
      10
      MIT
    • A
      license
      A
      quality
      Not graded
      maintenance
      Enables 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.
      4
      2
      AGPL 3.0