/diagnostic-dofile
Use this skill when the user needs to inspect, audit, or diagnose the safety of a Stata do-file. Typical scenarios include: uncertainty about whether a .do file is safe; receiving a complete do-file from an unofficial source (not the Stata website, not a well-known academic
$ npx -y skills add SepineTam/mcp-for-stata --skill diagnostic-dofile --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/diagnostic-dofile
Context preview
The summary Claude sees to decide when to auto-load this skill.
Use this skill when the user needs to inspect, audit, or diagnose the safety of a Stata do-file. Typical scenarios include: uncertainty about whether a .do file is safe; receiving a complete do-file from an unofficial source (not the Stata website, not a well-known academic
SKILL.md
diagnostic-dofile.SKILL.mdname: diagnostic-dofile
description: |
Use this skill when the user needs to inspect, audit, or diagnose the safety of a Stata do-file. Typical scenarios include: uncertainty about whether a .do file is safe; receiving a complete do-file from an unofficial source (not the Stata website, not a well-known academic institution or professor's official site); asking to check a batch of do-files; or requesting a read-only security/risk/portability diagnostic report. The skill does not modify the original file; it only emits a JSON report. Note that this is not a mandatory step for every do-file; run it only when a security review is warranted.
metadata:
version: "0.1.0"
Diagnostic do-file
This skill inspects a Stata do-file without changing the original file and outputs a JSON diagnostic report. The underlying script reuses `stata_mcp.utils.parse_dofile` and `stata_mcp.guard.blacklist`, so it handles Stata command abbreviations, prefixes (`capture` / `quietly`), macro expansion, block comments, `#delimit ;`, and other common constructs.
When to use
Recommended situations:
- You receive a complete do-file from an unknown or unofficial source, especially one downloaded from outside the Stata website or well-known academic/professor sites.
- The code arrives as an email attachment, cloud-drive link, forum post, or chat message, and you want to verify that it contains no dangerous commands or data-overwrite risks.
- Before taking over or reproducing someone else's project, you want to audit the key do-files.
- You explicitly want a read-only diagnostic report covering security, portability, encoding, and other dimensions.
This skill is not required every time you write a do-file. For analysis code you wrote yourself, understand, and trust, you can run it directly without generating a diagnostic report each time.
How to run
uv run plugins/stata-toolbox/skills/diagnostic-dofile/diagnose_dofile.py path/to/file.do
Save the report to a file:
uv run plugins/stata-toolbox/skills/diagnostic-dofile/diagnose_dofile.py path/to/file.do -o report.json
Current checks
1. File metadata
- File path, size, and modification time.
- UTC timestamp when the report was generated.
- SHA-256 hash of the file.
2. Encoding and format
- UTF-8 or UTF-8 with BOM.
- Non-UTF-8 encodings such as GBK/GB2312.
- Line ending: LF, CRLF, or mixed.
- Empty file or comment-only file.
3. Dangerous commands
Based on `src/stata_mcp/guard/blacklist.py`:
- Shell / system commands: `!`, `!!`, `shell`, `xshell`, `winexec`, `unixcmd`.
- File deletion: `erase`, `rm`, `rmdir`.
- External code execution: `do`, `run`, `include`.
- Embedded runtimes: `python`, `mata`, `java`, `plugin`.
- Package-management commands: `ssc`, `net`, `github`, `adoupdate`, `update`.
- Working-directory changes: `cd`, `chdir`.
4. Data-overwrite risks
- `use xxx.dta` followed by `save xxx.dta, replace` pointing to the same file.
- Memory-clearing operations such as `clear all` / `drop _all`.
5. Output-file overwrite
- `graph export xxx, replace`.
- `export xxx, replace`.
- Commands with `replace` such as `outreg2`, `esttab`, `estout`, `putexcel`, `putdocx`, `putpdf`, `logout`, `texdoc`.
- `log using xxx.log, replace`.
- `saveold xxx, replace`.
6. External commands / user-written packages
- Recognizes common external commands such as `reghdfe`, `estout`, `outreg2`, `esttab`, `coefplot`, `ivreg2`, `rdrobust`.
- Reports them so the caller can run Stata `help <command>` to verify installation.
7. Paths and portability
- Absolute paths such as `/Users/...` or `C:\...`.
- `webuse` or network URLs for loading data.
- `cd` / `chdir` working-directory changes.
8. Macro and parsing risks
- Unresolved macro variables (global macros, local macro expressions, etc.).
- Unclosed block comments, quotes, or program blocks that may affect parsing reliability.
Report format
The report is a JSON object with the following structure:
{
"schema_version": "0.1.0",
"generated_at": "2026-09-22T12:34:56.789012Z",
"file": {
"path": "/project/analysis.do",
"size_bytes": 1234,
"sha256": "abc123...",
"encoding": "utf-8",
"has_bom": false,
"line_ending": "lf"
},
"summary": {
"total_lines": 100,
"code_lines": 60,
"comment_lines": 30,
"blank_lines": 10,
"error_count": 2,
"warning_count": 5,
"info_count": 3
},
"findings": [
{
"level": "error",
"line": 12,
"category": "dangerous_command",
"message": "Detected dangerous command 'shell'"
}
]
}Notes
- The script only reads the original file and never modifies the do-file content.
- Findings are for reference only; the final execution decision is yours.
- For Stata-MCP, dangerous commands are automatically blocked by the security guard during `stata_do`. To disable the guard, configure `~/.statamcp/config.toml`, but this is not recommended.
Read more
name: diagnostic-dofile description: | Use this skill when the user needs to inspect, audit, or diagnose the safety of a Stata do-file. Typical scenarios include: uncertainty about whether a .do file is safe; receiving a complete do-file from an unofficial source (not the Stata website, not a well-known academic institution or professor's official site); asking to check a batch of do-files; or requesting a read-only security/risk/portability diagnostic report. The skill does not modify the original file; it only emits a JSON report. Note that this is not a mandatory step for every do-file; run it only when a security review is warranted. metadata: version: "0.1.0"
Diagnostic do-file
This skill inspects a Stata do-file without changing the original file and outputs a JSON diagnostic report. The underlying script reuses `stata_mcp.utils.parse_dofile` and `stata_mcp.guard.blacklist`, so it handles Stata command abbreviations, prefixes (`capture` / `quietly`), macro expansion, block comments, `#delimit ;`, and other common constructs.
When to use
Recommended situations:
- You receive a complete do-file from an unknown or unofficial source, especially one downloaded from outside the Stata website or well-known academic/professor sites.
- The code arrives as an email attachment, cloud-drive link, forum post, or chat message, and you want to verify that it contains no dangerous commands or data-overwrite risks.
- Before taking over or reproducing someone else's project, you want to audit the key do-files.
- You explicitly want a read-only diagnostic report covering security, portability, encoding, and other dimensions.
This skill is not required every time you write a do-file. For analysis code you wrote yourself, understand, and trust, you can run it directly without generating a diagnostic report each time.
How to run
uv run plugins/stata-toolbox/skills/diagnostic-dofile/diagnose_dofile.py path/to/file.do
Save the report to a file:
uv run plugins/stata-toolbox/skills/diagnostic-dofile/diagnose_dofile.py path/to/file.do -o report.json
Current checks
1. File metadata
- File path, size, and modification time.
- UTC timestamp when the report was generated.
- SHA-256 hash of the file.
2. Encoding and format
- UTF-8 or UTF-8 with BOM.
- Non-UTF-8 encodings such as GBK/GB2312.
- Line ending: LF, CRLF, or mixed.
- Empty file or comment-only file.
3. Dangerous commands
Based on `src/stata_mcp/guard/blacklist.py`:
- Shell / system commands: `!`, `!!`, `shell`, `xshell`, `winexec`, `unixcmd`.
- File deletion: `erase`, `rm`, `rmdir`.
- External code execution: `do`, `run`, `include`.
- Embedded runtimes: `python`, `mata`, `java`, `plugin`.
- Package-management commands: `ssc`, `net`, `github`, `adoupdate`, `update`.
- Working-directory changes: `cd`, `chdir`.
4. Data-overwrite risks
- `use xxx.dta` followed by `save xxx.dta, replace` pointing to the same file.
- Memory-clearing operations such as `clear all` / `drop _all`.
5. Output-file overwrite
- `graph export xxx, replace`.
- `export xxx, replace`.
- Commands with `replace` such as `outreg2`, `esttab`, `estout`, `putexcel`, `putdocx`, `putpdf`, `logout`, `texdoc`.
- `log using xxx.log, replace`.
- `saveold xxx, replace`.
6. External commands / user-written packages
- Recognizes common external commands such as `reghdfe`, `estout`, `outreg2`, `esttab`, `coefplot`, `ivreg2`, `rdrobust`.
- Reports them so the caller can run Stata `help <command>` to verify installation.
7. Paths and portability
- Absolute paths such as `/Users/...` or `C:\...`.
- `webuse` or network URLs for loading data.
- `cd` / `chdir` working-directory changes.
8. Macro and parsing risks
- Unresolved macro variables (global macros, local macro expressions, etc.).
- Unclosed block comments, quotes, or program blocks that may affect parsing reliability.
Report format
The report is a JSON object with the following structure:
{
"schema_version": "0.1.0",
"generated_at": "2026-09-22T12:34:56.789012Z",
"file": {
"path": "/project/analysis.do",
"size_bytes": 1234,
"sha256": "abc123...",
"encoding": "utf-8",
"has_bom": false,
"line_ending": "lf"
},
"summary": {
"total_lines": 100,
"code_lines": 60,
"comment_lines": 30,
"blank_lines": 10,
"error_count": 2,
"warning_count": 5,
"info_count": 3
},
"findings": [
{
"level": "error",
"line": 12,
"category": "dangerous_command",
"message": "Detected dangerous command 'shell'"
}
]
}Notes
- The script only reads the original file and never modifies the do-file content.
- Findings are for reference only; the final execution decision is yours.
- For Stata-MCP, dangerous commands are automatically blocked by the security guard during `stata_do`. To disable the guard, configure `~/.statamcp/config.toml`, but this is not recommended.
MCP-for-Stata is an safety first open-source MCP server and CLI tool with Skills lets any AI agent you use invoke local Stata on your device for regression analysis, econometrics, paper replication, and empirical research.
Other skills on mcp-for-stata.
rfc-impl-generator
Generate RFC and IMPL documents from a user-provided feature/fix description. Use when the user says something like "I want to…
stata-audit
Inspect, validate, summarize, and render local Stata-MCP audit evidence under .statamcp. Use when a user asks what tools ran,…
stata-discover
Use this skill when you need to find Stata on the user's machine or configure `stata-mcp` to use it. `stata-discover` provides…
stata-skill
A packaged Stata Runner skill via official MCP-for-Stata server including stata_do, ado_package_install, help, read_log and…

