Skip to main content
Glama

Server Configuration

Describes the environment variables required to run the server.

NameRequiredDescriptionDefault
STATA_DIRNoPath to the Stata installation directory. Defaults to automatic search (e.g. /Applications/Stata, /Applications/StataNow on macOS). Set this if Stata is not in a default location.
STATA_EDITIONNoStata edition: mp, se, or be. Defaults to automatic detection based on the installation directory.
STATA_MCP_WORKDIRNoProject working directory for the server. Defaults to automatic selection (session folder, otherwise the default directory).
STATA_MCP_DEFAULT_DIRNoDefault project directory when no session folder is available. Defaults to ~/Documents/Stata研究.
STATA_MCP_WAIT_SECONDSNoNumber of seconds to wait for a Stata command before returning; the task continues in the background and can be retrieved with stata_wait. Defaults to 240.
STATA_MCP_OUTPUT_SUBDIRNoName of the output subdirectory created under the project folder (containing do, logs, tables, figures). Defaults to stata_output.

Instructions

Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.

This server drives the user's OWN local Stata (official pystata engine, persistent session). Data, estimates, globals persist across calls until stata_restart.

Working rules:

  1. Before any econometric task, read stata_guide("workflow") and the topic guide (panel_fe, did, ddd, event_study, latex_tables, econ_standards). Follow them.

  2. Inspect data first (stata_data: overview / describe / xtdescribe) before modelling.

  3. Put real analysis in do-files via stata_do so it is reproducible; use stata_run for quick checks.

  4. estimates store every model, then export publication tables with stata_table (LaTeX/booktabs).

  5. Figures: build with Stata graph commands, then stata_graph to export PNG(+PDF) and show it.

  6. Outputs go to /stata_output/ (do/, logs/, tables/, figures/). Every command is also appended to logs/history_.do. Tell the user where files were saved.

  7. Never run shell escapes (!, shell) or delete user files. Ask before ssc install. Reply in the user's language.

Capabilities

Features and capabilities supported by this server

Protocol revision2025-11-25

CapabilityDetails
tools
{
  "listChanged": false
}
prompts
{
  "listChanged": false
}
resources
{
  "subscribe": false,
  "listChanged": false
}
experimental
{}

Tools

Functions exposed to the LLM to take actions

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

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.

stata_waitB

Keep waiting for a long-running Stata job started earlier and return its output.

stata_restartA

Kill and restart the Stata session (clears data in memory). Use if Stata hangs.

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.

stata_statusA

Show Stata install, working/output folders, and which key econometrics packages are installed.

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.

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.

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.

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

stata_helpA

Read the official Stata help file for a command (also works for installed packages, e.g. reghdfe, csdid).

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

Prompts

Interactive templates invoked by user choice

NameDescription

No prompts

Resources

Contextual data attached and managed by the client

NameDescription

No resources

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.