stata-preflight
Skill17 starsChanged 3 months agoMITView on GitHub
Use before editing or running any Stata .do file in the user's research projects. Checks for missing username path branches, `cap`-suppressed esttab calls, and other recurring Stata pitfalls. Catches issues that otherwise surface only as silent failures (no log produced, lost estimates).
In this repository14 other files it gives its agents.
- codex-bridgeSkill
- codex-review-planSkill
- overleafSkill
- plan-debateSkill
- power-firstSkill
- referee-panelSkill
- refresh-pipelineSkill
- review-codex-planSkill
- robustness-batterySkill
- spec-curve-sweepSkill
- sync-overleafSkill
- tableSkill
- verify-claimsSkill
- verify-numbers-pipelineSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 2 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Every do-file that sets paths needs a branch for each username:
- Distinctive: line 19
If a file is listed, the script will fail silently on that machine.
- Very specific: line 46
If missing, add one near the top so failures leave a diagnosable trail.
- Very specific: line 58
Add encoding("utf-8") to every hit.
- Very specific: line 76
Run batch Stata with the console binary (e.g.
- Very specific: line 79
Verify *.log was produced and mtime is recent.
- Very specific: line 81
If using esttab, confirm the output .tex/.csv was actually written and has content.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stata Pre-flight
Before running or finishing edits to any .do file, run these checks. The user's Stata username is <your-stata-username> (Stata base path /Users/<your-username>/). Check what c(username) actually reports on each machine — it can differ from the login name — and if you run Stata on more than one machine, path blocks need a branch for each.
1. Username path branches
Every do-file that sets paths needs a branch for each username:
grep -L '"<your-stata-username>"' path/to/file.do # listed = missing this machine's branch
grep -L '"<other-machine-username>"' path/to/file.do # listed = missing the other machine's branchIf a file is listed, the script will fail silently on that machine. Add the missing branch:
if "`c(username)'" == "<your-stata-username>" {
global root "/Users/<your-username>/.../<project>"
}
if "`c(username)'" == "<other-machine-username>" {
global root "/Users/<other-username>/.../<project>"
}2. No cap around esttab
grep -nE "(^|[^a-z])cap(ture)?[[:space:]]+esttab" path/to/file.doAny hit must be unwrapped. cap esttab silently drops in-memory estimates, producing empty tables. Same goes for cap est store chains that feed esttab.
3. Log file declared
Confirm the do-file opens a log:
grep -nE "^log using" path/to/file.doIf missing, add one near the top so failures leave a diagnosable trail. Follow it with
set linesize 255 so long lines (MDE, N, long variable lists) aren't truncated in the log.
A PostToolUse hook that checks .do files on every edit can repeat checks 1–3; checks 4–5
are only here.
4. Text imports declare UTF-8
grep -n "import delimited" path/to/file.do | grep -v "encoding("Add encoding("utf-8") to every hit. Without it Stata may pick ISO-8859-1 (the log says
"encoding automatically selected: ISO-8859-1"), and accented names (Crédit Agricole, Société
Générale) then fail string merges with no error — rows drop silently. Fix every import in a
pipeline at once so N stays consistent across tables.
5. esttab label text
In labels() / postfoot() strings Stata expands macros before writing the file:
"KP $F$-stat"→$Fis read as an empty global →KP $-stat. Write\$F\$.``Rung''→ the backticks open a local-macro reference and the phrase vanishes. Use\textquotedblleft Rung\textquotedblright{}.
Both compile with no error, so grep the emitted .tex for the literal label text. When
patching a do-file from Python, use raw strings so \$ and backticks survive.
6. After running
- Run batch Stata with the console binary (e.g.
.../StataSE.app/Contents/MacOS/stata-se -b do <file>) through a wrapper do-file in a space-free directory (do "<quoted path>") — batch Stata chokes on spaces in the-b dopath. - Verify
*.logwas produced and mtime is recent. - Open the tail of the log and confirm no
r(xxx);errors before declaring success. - If using
esttab, confirm the output.tex/.csvwas actually written and has content.
Reporting
Report each check as PASS/FAIL. If anything is FAIL, do not run the script — fix first.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

