Stata Code logo

Stata Code

Run Stata analyses from MCP clients with structured results, diagnostics, econometric workflows, and publication-ready tables.

Install Stata Code

Pick your client, then add it in one click or paste the config.

STDIOPython
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "stata-code": {
      "command": "uvx",
      "args": [
        "--from",
        "stata-code[mcp]",
        "stata-code-mcp"
      ]
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Automated check passed— started and listed 23 tools correctly ().

Overview

stata-code connects AI agents and developer tools to a local Stata installation through a shared Python core. Its MCP server runs Stata code and returns structured results, including typed errors, native r() and e() values, logs, and graph references. Built-in workflows cover DiD, IV, RDD, publication tables, and optional StatsPAI cross-validation. Reach for it when an agent needs to run and inspect Stata-based empirical research from Claude Code, Cursor, Claude Desktop, VS Code, or a compatible MCP client.

Use cases

  • Run difference-in-differences and event-study analyses from an MCP client
  • Generate publication-ready Stata tables through an agent workflow
  • Cross-check ATT estimates with StatsPAI
  • Diagnose and selectively rerun failed Stata do-files
  • Execute Stata code from Jupyter or VS Code

Key features

  • Structured Stata results with typed errors
  • DiD, IV, RDD, and publication-table workflows
  • Stata 17+ pystata and Stata 13+ console backends
  • MCP server, Jupyter kernel, CLI, and VS Code frontends
  • Native r() and e() result access
  • StatsPAI cross-validation workflow

Tools23

What Stata Code lets your agent do. Expand a tool for its parameters.

Verified live~6.1k tokens of context

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

7/7 checks healthy over the last 17d

What it can do

From the 23 tools this server returned when we ran it; 23 declare their own safety hints.

Runs commands · 4Can delete or modify data · 8Makes changes · 9Handles credentials · 2Makes network requests · 9Read-only tools · 12
Network at startup2 connections
Files written at startup11

Observed 2026-11-29 in an isolated sandbox. A description of reach, not a security audit.

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 2d ago via OSV.dev · stata-code-mcp (PyPI)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

GitHub stars56Stargazers on the source repository.
Last commit5d agoMost recent push to the default branch.
Availability100%Our rolling endpoint + install checks that succeeded.
Install checkPassedOur sandbox started it and listed its tools.
Tools exposed23Callable tools this server registers over MCP.

How Stata Code works

What stata-code does

stata-code provides an agent-facing bridge to locally installed Stata. The same Python core supports an MCP server, a Jupyter kernel, a VS Code extension, and the stata-code run command-line interface. These entry points use a shared result format intended to reduce unnecessary output while preserving information agents need to interpret a run.

The project targets empirical economics workflows. Its included guidance and prompts cover difference-in-differences, instrumental variables and weak-instrument checks, regression discontinuity, table generation with esttab, and cross-package or cross-stack parity checks. StatsPAI can be used to re-estimate an ATT and compare results across implementations.

How it works

The core can run through either of two Stata backends. Stata 17 and later can use the bundled pystata integration for in-memory sessions, while Stata 13 and later can use a console backend without pystata. Both backends return the same result schema. Stata frames support multiple sessions in the core.

For MCP use, an agent can call stata_run with Stata code or a do-file workflow. Failed runs return structured error information such as the error kind, source line, context, and suggested next steps. An agent may use those fields to repair and rerun a do-file only when the user explicitly requests that behavior; failure handling is diagnostic by default.

The repository also includes reusable prompts such as did_event_study, iv_2sls, rdd, publication_table, and cross_validate_did. These prompts draw on recipes in the packaged skill resources rather than requiring every workflow to be written from scratch.

Setup and configuration

The package requires Python 3.10 or newer and a local Stata installation. Install the base package with:

Terminal
pip install stata-code

Install the MCP and Jupyter extras when those frontends are needed:

Terminal
pip install "stata-code[mcp,kernel]"

For a quick MCP setup with Claude Code, use uvx:

Terminal
claude mcp add stata-code --scope user -- uvx --from "stata-code[mcp]" stata-code-mcp

The package looks for Stata's pystata files in standard installation locations. If Stata is installed elsewhere, add its pystata directory to PYTHONPATH before importing the package. The stata-code doctor command checks Python and package details, optional extras, Stata discovery, console commands, and common MCP client configuration locations. Use --json for machine-readable diagnostics.

To add the Jupyter frontend, install the kernel extra and register the kernel with stata-code-kernel install --user. The resulting Stata kernel can be selected in Jupyter Notebook, JupyterLab, and VS Code's Jupyter extension.

Tools and capabilities

  • Execute Stata code through the MCP server or CLI.
  • Return compact, structured results with typed errors and native r() and e() values.
  • Expose log and graph references instead of requiring agents to process all output inline.
  • Run recipe-backed DiD, IV, RDD, publication-table, and cross-validation workflows.
  • Use Stata 17+ with pystata or Stata 13+ through the console backend.
  • Share the core across MCP, Jupyter, VS Code, and terminal frontends.

Limitations and notes

Stata must be installed separately; pystata is distributed with Stata rather than through PyPI. The console backend is stateless, while the pystata backend supports in-memory sessions. Cross-validation with StatsPAI covers the Stata side of the workflow and relies on explicit handoffs to independent R, Python, or data MCP tools. Automatic repair and rerunning after an error is opt-in rather than the default behavior.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about Stata Code

stata-code is an MCP server that connects AI agents to locally installed Stata through a shared Python core, exposing Stata execution, structured results, error diagnostics, and workflows for DiD, IV, RDD, and publication tables. It can also support cross-validation with StatsPAI.

Install it with `pip install "stata-code[mcp]"`, or register it with Claude Code using the documented `uvx --from "stata-code[mcp]" stata-code-mcp` command. Python 3.10 or newer and a local Stata installation are required.

stata-code supports Stata 17 and later through `pystata`, and Stata 13 and later through its console backend. The console option does not require `pystata`, while the two backends expose the same result schema.

Yes. Cursor is named as a supported agent frontend for stata-code. The MCP server can be configured for Cursor like other compatible MCP servers, provided the client can launch the server and the machine has a usable Stata installation.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewStata Code AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/stata-code?style=directory)](https://allmcps.com/mcp/stata-code)
HTML Embed
<a href="https://allmcps.com/mcp/stata-code"><img src="https://allmcps.com/api/badge/stata-code?style=directory" alt="Stata Code on AllMCPs" /></a>