Stata MCP Server
io.github.aliveranme/stata-mcp·v1.0.10通过 pystata 驱动真实 Stata 的 MCP 服务器:数据加载/清洗/建模/诊断/图形导出,75 个工具覆盖完整计量工作流。
0 stars95 downloads/wk
Reviews
Write oneNobody has reviewed Stata MCP Server yet.
If you have run it, two minutes of your experience saves the next person an afternoon.
Stata MCP Server tools (75, 4 write)
write = sends, deletes, buys or postsRead from the package source without running it. The installed server may list more.
stata_append纵向追加数据集(``append``)。
stata_background在后台执行 Stata 命令,立即返回任务号,不阻塞当前请求。
stata_clear重置 / 清空当前 Stata 会话状态。
stata_codebook生成数据集的 Codebook(变量字典)。
stata_collapse按组聚合,把数据集**就地替换**为汇总结果(``collapse``)。
stata_correlate计算相关系数矩阵。
stata_describe描述当前数据集的变量信息。
stata_describe_package查看某个扩展包的详情(作者、功能、包含的文件)。
stata_destring把字符串变量转为数值变量(destring)。
stata_display计算并显示 Stata 表达式的结果。
stata_dropwrite action删除变量或观测(drop)。
stata_egen用扩展生成函数创建新变量(egen)。
stata_estat运行后估计诊断(``estat``)。
stata_estimates管理已存储的估计结果(``estimates``)。
stata_etable生成回归结果表并可导出(官方 ``etable``,Stata 17+)。
stata_export_delimited将当前数据集导出为分隔文本文件(CSV / TSV / 自定义分隔符)。
stata_export_excel将当前数据集导出为 Excel (.xlsx/.xls) 文件,或将回归结果导出为 CSV。
stata_find_package搜索可安装的 Stata 扩展包(联网)。
stata_frame管理数据 frame —— 在内存中同时持有多个数据集(Stata 16+)。
stata_generate创建新变量(generate)。
stata_graph生成 Stata 图形并可选导出为文件。
stata_hausman对两个已存储的估计结果做 Hausman 设定检验(``hausman``)。
stata_help查询任意 Stata 命令的官方帮助文档(语法、选项、示例)。
stata_import导入非 .dta 格式的数据文件(与 stata_export_* 对称)。
stata_install_package安装 Stata 扩展包(联网)。
stata_ivregress运行工具变量回归(ivregress,2SLS/LIML/GMM)。
stata_keep保留变量或观测,删除其余(keep)。
stata_lincom对当前估计结果做线性组合的 Wald 检验(``lincom``)。
stata_list列出当前数据集中的数据值。
stata_list_packages列出当前已安装的所有 Stata 扩展包(包名 + 一句简介)。
stata_list_resources列出本会话全部已登记的文件资源。
stata_logistic运行 Logistic 回归分析。
stata_logit运行 Logit 回归分析。
stata_margins估计边际效应 / 预测边际(margins,后估计命令)。
stata_merge横向合并数据集(``merge``)。
stata_mixed运行多层混合效应线性回归(multilevel mixed-effects,mixed)。
stata_mlogit运行多分类 Logit 回归分析(multinomial logit)。
stata_more翻页浏览上一条 Stata 命令的完整输出。
stata_nbreg运行负二项回归分析(negative binomial regression)。
stata_nlcom对当前估计结果做非线性组合的 delta 法检验(``nlcom``)。
stata_ping心跳检测 — 快速测试 Stata MCP Server 是否存活。
stata_poisson运行 Poisson 回归(计数因变量)。
stata_predict在估计后生成预测值 / 残差等(predict,后估计命令)。
stata_probit运行 Probit 回归(二元因变量)。
stata_qreg运行分位数回归(quantile regression,qreg)。
stata_read_file读取本会话导出/登记的文件(**实际内容**,而不仅是路径)。
stata_read_log读取本 MCP Server 自身的运行日志(stata-mcp.log)。
stata_recode按规则组重编码变量取值(recode)。
stata_register_file把磁盘上已有的文件显式登记为可读资源。
stata_regress运行线性回归分析 (OLS)。
stata_rename重命名变量(rename)。
stata_replace替换既有变量的取值(replace)。
stata_reshape长宽表互转(``reshape``)。
stata_return_list一次列出全部返回值(``return`` / ``ereturn`` / ``creturn list``)。
stata_runwrite action执行一条或多条 Stata 命令并返回输出。
stata_run_do_filewrite action执行一个 Stata .do 文件并返回全部输出。
stata_save_dataset将当前内存中的数据集保存为 .dta 文件。
stata_scheme查询或设置 Stata 图形主题(scheme)。
stata_set_cwd更改 Stata 的工作目录。
stata_snapshot会话内快照:保存 / 恢复 / 列出 / 删除当前内存数据集。
stata_status获取当前 Stata 会话状态。
stata_summarize计算变量的摘要统计量。
stata_tabulate创建频数分布表或交叉表。
stata_task_cancelwrite action请求取消一个运行中的后台任务。
stata_task_list列出全部(含已结束的)后台任务。
stata_task_result获取后台任务的完整输出结果。
stata_task_status查询后台任务的状态与进度。
stata_test对上一个估计结果做 Wald 检验(test,后估计命令)。
stata_ttest运行 t 检验(单样本 / 按组两样本 / 配对 / 非配对)。
stata_uninstall_package卸载一个已安装的 Stata 扩展包(删除其 ado 文件)。
stata_use_dataset加载 Stata 数据集 (.dta 文件) 到内存中。
stata_use_example加载 Stata 官方示例数据集(``sysuse`` / ``webuse``)。
stata_verify数据完整性检查(``count`` / ``assert`` / ``duplicates`` / ``isid`` / ``misstable``)。
stata_xtreg运行面板数据回归(xtreg)。
stata_xtset声明面板 / 时间序列结构(``xtset`` / ``tsset``)。
Public scan report
scanner v0.1.10 · 2026-11-03 · same rubric, same numbers if you re-run it
- Code scan17 source files scanned25/25
- –Live reliabilityno gateway calls yet and no remote to proben/a
- –Tool poisoningtools not inspected (local package is not executed); not countedn/a
- Auth qualitylocal package, no credentials required12/15
- Maintenancelast push 65 days ago12/15
- Maintainer identityregistry namespace matches repository owner; GitHub account older than a year8/10
How Stata MCP Server compares
Against every graded MCP server, from our own scans and uptime checks. Updated after each scan run.
- Safety score
- 88/100
- higher than 75% of 48,255 servers
- Tools
- 75
- the typical server has 7
- Tools that change things
- 5%
- typical: 0%. Fewer write tools means less an agent can break
- Downloads a week
- 95
- more than 62% of 12,191 servers with a package
What its tools let an agent do: 71 read · 4 change
Install Stata MCP Server in Claude Code, Cursor or VS Code
Runs npx -y @aliveranme/stata-mcp on your machine. Read the scan report first; the gateway never runs local packages.
claude mcp add stata-mcp -- npx -y @aliveranme/stata-mcp
What the publisher says
From the Stata MCP Server repository's README, as published. We do not edit it. Read it on GitHub
<!-- mcp-name: io.github.aliveranme/stata-mcp -->
在 Claude Code 里用自然语言做 Stata 分析。你描述要什么,Agent 自己写命令、执行、 读结果、继续下一步 —— 加载数据、清洗、建模、诊断、导出,全在一个持久的 Stata 会话里完成,数据不用反复载入。
一句话,跑完整个分析
你: 加载 auto.dta,用 weight 和 mpg 回归 price,并检查异方差
Agent 自动完成(无需你写任何 Stata 命令):
stata_use_dataset("auto.dta") → 74 obs, 12 vars 已载入
stata_regress("price", "weight mpg") → R² = 0.293 ; weight 1.75 (p=0.008)
stata_run("estat hettest") → Breusch–Pagan χ² 检验异方差
stata_graph("rvfplot", export="…png") → 残差图导出为文件数据从第一步起就留在内存里,后面每一步都接着用 —— 这正是 stata_run("regress …") 之外还值得有一个 MCP Server 的原因。
这是什么
两部分组成,一起装进 Claude Code:
暴露给 Agent。statarun 执行任意命令、statahelp 查任意命令的官方语法,二者 合起来即「全量内置命令支持」;其余专用工具(回归 / 面板 / IV / 生成变量 / 数据 清洗 / 后估计 / 文件资源 / 后台任务 …)是给高频命令加结构化参数与校验的便利层。
- 执行层(MCP Server) —— 经 pystata 直接调用 Stata 的运行时,把 75 个工具
地图与常用外置包。Agent 据此知道该用什么命令,而不是靠猜。
- 知识层(Skill) —— 一份 Stata 编程指南:语法要点、分析模板、常见陷阱、命令
为什么是 pystata,而不是 subprocess
pystata 通过 ctypes 在进程内加载 Stata 运行时,而非每条命令起一个子进程:
宏在所有工具调用之间保持。多步分析(加载 → 清洗 → 回归 → 诊断)就是自然的对话。
- 真会话持久 —— Stata 在 MCP Server 启动时初始化一次,数据集、估计结果、局部
硬上限 120K 字符防止撑爆 MCP 通道;长命令有 60s 超时看门狗(可显式调大)。
- 低延迟 —— 无进程启动开销,单条命令约 12ms。
- 输出可控 —— 直接读 Stata 输出缓冲;大输出自动分页(stata_more 翻页),
架构
快速开始
前置条件
- Stata:StataNow 19 或 Stata 18+(MP / SE / BE 均可)——需含 utilities/pystata
- Python 3.10+(推荐 3.12+)
- Claude Code 最新版
- 操作系统:Windows 或 macOS(见下方「兼容性」)
一键安装
git clone https://gitea.aliveranme.space/aliveranme/stata-mcp.git
cd stata-mcp
python setup.py装在非标准位置(如外置卷 /Volumes/xxx/Applications/StataNow)时自动检测会失败 ——
先 export STATA_HOME=/你的/Stata路径 再跑 setup.py 即可。
setup.py 会:检测 Stata 安装(常见路径 + STATA_HOME 环境变量,跨平台)→ 创建虚拟环境并安装 fastmcp → 生成 .mcp.json(保留你已有的其他 MCP Server 配置) → 验证 Server 可启动。
手动安装(自动检测失败时)
# 1. 指定 Stata 路径(替换为你本机实际路径)
export STATA_HOME="C:/Program Files/StataNow/StataNow19" # Windows
# export STATA_HOME="/Applications/Stata" # macOS
export STATA_EDITION=mp # mp / se / be
# 2. 建虚拟环境并装依赖
cd mcp-stata-server
uv venv
source .venv/Scripts/activate # Windows Git Bash
# source .venv/bin/activate # macOS / Linux
uv pip install "fastmcp>=3.2.0"
# 3. 生成配置
cd ..
cp .mcp.json.example .mcp.json # 编辑其中的 <repo-path>通过 npm 安装(无需 clone 仓库)
若你已有 Node.js ≥ 18 与 uv(无 uv 时需 Python 3.10+ 且已装 fastmcp>=3.2.0),可直接使用已发布的 npm 包 @aliveranme/stata-mcp:
export STATA_HOME="/你的/Stata路径" # 含 utilities/pystata
export STATA_EDITION=mp
# 直接跑通(首次启动经 uv 拉取 fastmcp,请给客户端 90s 超时)
npx -y @aliveranme/stata-mcpClaude Code .mcp.json 配置:
{
"mcpServers": {
"stata": {
"command": "npx",
"args": ["-y", "@aliveranme/stata-mcp"],
"env": { "STATA_HOME": "/Applications/StataNow", "STATA_EDITION": "mp" }
}
}
}Shortened. The full README is on GitHub.
Nothing above is checked by us. What we check is on the safety report.
Stata MCP Server: common questions
- Is Stata MCP Server safe?
- Yes, by our scan: it is graded A (88/100). Read the Stata MCP Server safety report
- How do I install Stata MCP Server?
- It runs on your machine. Copy the Claude Code, Cursor, VS Code or Claude Desktop config from the install section.
- Does Stata MCP Server need an API key?
- No secret keys are declared. It reads 3 settings from the environment.
- Is Stata MCP Server maintained?
- The last commit was 66 days ago (2026-08-30). The latest release is v1.0.10.
- How does Stata MCP Server compare with other MCP servers?
- safety score 88/100 (higher than 75% of 48,255 servers); tools 75 (the typical server has 7); tools that change things 5% (typical: 0%. Fewer write tools means less an agent can break). Full comparison.