SkillAgentSearch skills...

stata

Comprehensive Stata reference for writing correct .do files, data management, econometrics, causal inference, graphics, Mata programming, and 20 community packages (reghdfe, estout, did, rdrobust, etc.). Covers syntax, options, gotchas, and idiomatic patterns.

Install / Use

npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata

Installs into whichever agent you are using.

About this skill
๐Ÿ“„

SKILL.md

Installable skill definition

Quality Score

95/100

Supported Platforms

Universal

Tags

Our assessment of stata

stata scores 95/100 on our quality scale, 124th of 1,153 Content & Media skills we index (top 11%).

Its SKILL.md is 16 KB long, well organised into 45 sections with 22 code examples: a thorough specification that gives an agent plenty to work with.

With 4,360 GitHub stars, it is one of the more widely adopted skills in the catalogue.

Substance
30/30
Structure
20/20
Description
15/15
Adoption
15/20
Freshness
15/15

Maintenance, license and trust

  • The repository was last updated about 2 months ago, so stata is actively maintained.
  • Our last check on 2026-11-15 found the source still online.
  • No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
  • Its trust signals score 88/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit โ€” read the skill file before letting an agent act on it.

Safety scan

No issues found

Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful.

AI review by kimi-k2.7-code on 2026-09-29. Automated pattern scan on 2026-09-29. It catches known dangerous patterns, not every risk โ€” read a skill before letting an agent act on it.

stata compared with similar skills

All 4 of these similar skills score higher than stata; compare them before choosing.

SkillScoreStarsUpdatedFormat
stata (this skill)by brycewang-stanford954.4k54d agoSKILL.md
siyuanby siyuan-note10047.3ktodayMCP Server
x402by browser-use100121.0k3d agoSKILL.md
algorithmic-artby anthropics100177.9k55d agoSKILL.md
pptxby anthropics100177.9k55d agoSKILL.md

Frequently asked questions

How do I install stata?
Run npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata. The install tabs above show the steps for each supported agent.
Which AI agents does stata work with?
It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
Is stata safe to use?
Our scan of the whole file found no instruction hijacking, hidden characters, credential access, data exfiltration or destructive commands. An AI review of the same text found nothing harmful. It declares no license and scores 88/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
Is stata still maintained?
The repository was last updated about 2 months ago, so stata is actively maintained.

name: stata description: > Comprehensive Stata reference for writing correct .do files, data management, econometrics, causal inference, graphics, Mata programming, and 20 community packages (reghdfe, estout, did, rdrobust, etc.). Covers syntax, options, gotchas, and idiomatic patterns. Use this skill whenever the user asks you to write, debug, or explain Stata code.

Stata Skill

You have access to comprehensive Stata reference files. Do not load all files. Read only the 1-3 files relevant to the user's current task using the routing table below.


Critical Gotchas

These are Stata-specific pitfalls that lead to silent bugs. Internalize these before writing any code.

Missing Values Sort to +Infinity

Stata's . (and .a-.z) are greater than all numbers.

* WRONG โ€” includes observations where income is missing!
gen high_income = (income > 50000)

* RIGHT
gen high_income = (income > 50000) if !missing(income)

* WRONG โ€” missing ages appear in this list
list if age > 60

* RIGHT
list if age > 60 & !missing(age)

= vs ==

= is assignment; == is comparison. Mixing them up is a syntax error or silent bug.

* WRONG โ€” syntax error
gen employed = 1 if status = 1

* RIGHT
gen employed = 1 if status == 1

Local Macro Syntax

Locals use `name' (backtick + single-quote). Globals use $name or ${name}. Forgetting the closing quote is the #1 macro bug.

local controls "age education income"
regress wage `controls'        // correct
regress wage `controls         // WRONG โ€” missing closing quote
regress wage 'controls'        // WRONG โ€” wrong quote characters

by Requires Prior Sort (Use bysort)

* WRONG โ€” error if data not sorted by id
by id: gen first = (_n == 1)

* RIGHT โ€” bysort sorts automatically
bysort id: gen first = (_n == 1)

* Also RIGHT โ€” explicit sort
sort id
by id: gen first = (_n == 1)

Factor Variable Notation (i. and c.)

Use i. for categorical, c. for continuous. Omitting i. treats categories as continuous.

* WRONG โ€” treats race as continuous (e.g., race=3 has 3x effect of race=1)
regress wage race education

* RIGHT โ€” creates dummies automatically
regress wage i.race education

* Interactions
regress wage i.race##c.education    // full interaction
regress wage i.race#c.education     // interaction only (no main effects)

generate vs replace

generate creates new variables; replace modifies existing ones. Using generate on an existing variable name is an error.

gen x = 1
gen x = 2          // ERROR: x already defined
replace x = 2      // correct

String Comparison Is Case-Sensitive

* May miss "Male", "MALE", etc.
keep if gender == "male"

* Safer
keep if lower(gender) == "male"

merge Always Check _merge

Never skip tab _merge โ€” it costs nothing and is the only diagnostic you get when assert fails.

merge 1:1 id using other.dta
tab _merge                      // ALWAYS tab before assert
assert _merge == 3              // fails silently without tab output
drop _merge

preserve / restore + tempfile for Collapse-Merge-Back

The standard pattern for computing group stats and merging them onto the original data:

tempfile stats
preserve
collapse (mean) avg_x=x, by(group)
save `stats'
restore
merge m:1 group using `stats'
tab _merge
assert _merge == 3
drop _merge

For simple group means, bysort group: egen avg_x = mean(x) avoids the round-trip entirely.

Weights Are Not Interchangeable

  • fweight โ€” frequency weights (replication)
  • aweight โ€” analytic/regression weights (inverse variance)
  • pweight โ€” probability/sampling weights (survey data, implies robust SE)
  • iweight โ€” importance weights (rarely used)

capture Swallows Errors

capture some_command
if _rc != 0 {
    di as error "Failed with code: " _rc
    exit _rc
}

Line Continuation Uses ///

regress y x1 x2 x3 ///
    x4 x5 x6, ///
    vce(robust)

Stored Results: r() vs e() vs s()

  • r() โ€” r-class commands (summarize, tabulate, etc.)
  • e() โ€” e-class commands (estimation: regress, logit, etc.)
  • s() โ€” s-class commands (parsing)

A new estimation command overwrites previous e() results. Store them first:

regress y x1 x2
estimates store model1

Running Stata from the Command Line

Claude can execute Stata code by running .do files in batch mode from the terminal. This is how to run Stata non-interactively.

Finding the Stata Binary

Stata on macOS is a .app bundle. The actual binary is inside it. Common locations:

# Stata 18 / StataNow (most common)
/Applications/Stata/StataMP.app/Contents/MacOS/stata-mp
/Applications/StataNow/StataMP.app/Contents/MacOS/stata-mp

# Other editions (SE, BE)
/Applications/Stata/StataSE.app/Contents/MacOS/stata-se
/Applications/Stata/StataBE.app/Contents/MacOS/stata-be

If Stata isn't on $PATH, find it with: mdfind -name "stata-mp" | grep MacOS

Batch Mode (-b)

# Run a .do file in batch mode โ€” output goes to <filename>.log
/Applications/Stata/StataMP.app/Contents/MacOS/stata-mp -b do analysis.do

# If stata-mp is on PATH (e.g., via symlink or alias):
stata-mp -b do analysis.do
  • -b = batch mode (non-interactive, no GUI)
  • Output (everything Stata would display) is written to analysis.log in the working directory
  • Exit code is 0 on success, non-zero on error
  • The log file contains all output, including error messages โ€” check it after execution

Running Inline Stata Code

To run a quick Stata snippet without creating a .do file:

# Write a temp .do file and run it
cat > /tmp/stata_run.do << 'EOF'
sysuse auto, clear
summarize price mpg
EOF
stata-mp -b do /tmp/stata_run.do
cat /tmp/stata_run.log

Checking Results

# Check if it succeeded
stata-mp -b do tests/run_tests.do && echo "SUCCESS" || echo "FAILED"

# Search the log for pass/fail
grep -E "PASS|FAIL|error|r\([0-9]+\)" run_tests.log

Tips

  • clear all at the top of batch scripts โ€” batch mode starts with a fresh Stata session, but clear all ensures no stale state from prior runs in the same session.
  • set more off โ€” prevents Stata from pausing for --more-- prompts (fatal in batch mode).
  • Log files overwrite silently โ€” analysis.do always writes to analysis.log in the current directory. If you run multiple .do files, check the right log.
  • Working directory โ€” Stata's working directory is wherever you run the command from, not where the .do file lives. Use cd in the .do file or absolute paths if needed.

Routing Table

Read only the files relevant to the user's task. Paths are relative to this SKILL.md file.

Data Operations

| File | Topics & Key Commands | |------|----------------------| | references/basics-getting-started.md | use, save, describe, browse, sysuse, basic workflow | | references/data-import-export.md | import delimited, import excel, ODBC, export, web data | | references/data-management.md | generate, replace, merge, append, reshape, collapse, recode, egen, encode/decode | | references/variables-operators.md | Variable types, byte/int/long/float/double, operators, missing values (.<.a), if/in qualifiers | | references/string-functions.md | substr(), regexm(), strtrim(), split, ustrlen(), regex, Unicode | | references/date-time-functions.md | date(), clock(), %td/%tc formats, mdy(), dofm(), business calendars | | references/mathematical-functions.md | round(), log(), exp(), abs(), mod(), cond(), distributions, random numbers |

Statistics & Econometrics

| File | Topics & Key Commands | |------|----------------------| | references/descriptive-statistics.md | summarize, tabulate, correlate, tabstat, codebook, weighted stats | | references/linear-regression.md | regress, vce(robust), vce(cluster), test, lincom, margins, predict, ivregress | | references/panel-data.md | xtset, xtreg fe/re, Hausman test, xtabond, dynamic panels | | references/time-series.md | tsset, ARIMA, VAR, dfuller, pperron, irf, forecasting | | references/limited-dependent-variables.md | logit, probit, tobit, poisson, nbreg, mlogit, ologit, margins for nonlinear | | references/bootstrap-simulation.md | bootstrap, simulate, permute, Monte Carlo | | references/survey-data-analysis.md | svyset, svy:, subpop(), complex survey design, replicate weights | | references/missing-data-handling.md | mi impute, mi estimate, FIML, misstable, diagnostics | | references/maximum-likelihood.md | ml model, custom likelihood functions, ml init, gradient-based optimization | | references/gmm-estimation.md | gmm, moment conditions, estat overid, J-test |

Causal Inference

| File | Topics & Key Commands | |------|----------------------| | references/treatment-effects.md | teffects ra/ipw/ipwra/aipw, stteffects, ATE/ATT/ATET | | references/difference-in-differences.md | DiD, parallel trends, event studies, staggered adoption | | references/regression-discontinuity.md | Sharp/fuzzy RD, bandwidth selection, rdplot | | references/matching-methods.md | PSM, nearest neighbor, kernel matching, teffects nnmatch | | references/sample-selection.md | heckman, heckprobit, treatment models, exclusion restrictions |

Advanced Methods

| File | Topics & Key Commands | |------|----------------------| | references/survival-analysis.md | stset, stcox, streg, Kaplan-Meier, parametric models | | references/sem-factor-analysis.md | sem, gsem, CFA, path analysis, alpha, reliability | | references/nonparametric-methods.md | kdensity, rank tests, qreg, npregress | | references/spatial-analysis.md | spmatrix, spregress, spatial weights, Moran's I | | references/machine-learning.md | lasso, elasticnet, cvlasso, cross-validation |

Graphics

| File | Topics & Key Commands | |------|----------------------| | references/graphics.md | twoway, scatter, line, bar, histogram, graph combine, graph export, schemes |

Programming

| File | Topics & Key Commands | |------|----------------------| | references/programming-basics.md | local, global, foreach, forvalues, program define, syntax, return | | references/advanced-programming.md | syntax, mata, classes, _prefix, dialog boxes, tempfile/tempvar | | references/mata-introduction.md | Mata basics, when to use Mata vs ado, data types | | references/mata-programming.md | Mata functions, flow control, structures, pointers | | references/mata-matrix-operations.md | Matrix creation, decompositions, solvers, st_matrix() | | references/mata-data-access.md | st_data(), st_view(), st_store(), performance tips |

Output & Workflow

| File | Topics & Key Commands | |------|----------------------| | references/tables-reporting.md | putexcel, putdocx, putpdf, LaTeX integration, collect | | references/workflow-best-practices.md | Project structure, master do-files, version control, debugging, common mistakes | | references/external-tools-integration.md | Python via python:, R via rsource, shell commands, Git | | references/filing-issues.md | User wants to report a Stata skill documentation gap or error to the repository |

Community Packages

| File | What It Does | |------|-------------| | packages/reghdfe.md | High-dimensional fixed effects OLS (absorbs multiple FE sets efficiently) | | packages/estout.md | esttab/estout: publication-quality regression tables | | packages/outreg2.md | Alternative regression table exporter (Word, Excel, TeX) | | packages/asdoc.md | One-command Word document creation for any Stata output | | packages/tabout.md | Cross-tabul

Truncated for display โ€” read the full file on GitHub.

Related Skills

View on GitHub
GitHub Stars4.4k
CategoryContent
Updated1mo ago
Forks527

Languages

Stata

Trust signals

88/100

From repository metadata: license, adoption, age and documentation. Not a code audit โ€” see the Safety scan above for what the skill file itself contains.

1 medium
stata โ€” Universal Skill: Install & Safety Check | SkillAgent