.claude/skills/script-translator/SKILL.md
Use this skill whenever the user wants to translate, convert, or port a script from one statistical programming language to another — STATA, Python (pandas/numpy/statsmodels), or R (tidyverse/base R). Trigger even if the user says 'rewrite in R', 'convert to Python', 'port to STATA', or asks how code would look in another language.
npx skillsauth add AndreaMentasti/tweet-election script-translatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Faithful line-by-line translation between Stata, Python, and R.
From the user message: Look for keywords like "to Python", "in R", "port to Stata", "convert to R", "rewrite in Python".
From file extension:
.do → Stata.py → Python.R / .r → RIf ambiguous: Ask the user to confirm source and target before proceeding.
Before writing ANY translated code, read the relevant body file:
| Direction | File to read |
|-----------|-------------|
| Python → R | bodies/python-to-r.md |
| Python → Stata | bodies/python-to-stata.md |
| R → Python | bodies/r-to-python.md |
| R → Stata | bodies/r-to-stata.md |
| Stata → Python | bodies/stata-to-python.md |
| Stata → R | bodies/stata-to-r.md |
The body file contains the construct mapping table, idiomatic equivalences, required imports, and known traps for that specific pair. Follow it closely.
These rules are absolute and override any instinct to "improve" the code:
# REVIEW: possible bug in original# Stata's egen mean() equivalent)# REVIEW: any construct that has no direct equivalent or requires manual verificationThe translated script must produce statistically identical results:
robust (HC1) stays HC1. cluster(var) stays clustered at the same variable. Never change the SE type or clustering level. Verify the target language's default matches (e.g., Stata robust = HC1, statsmodels HC1 = HC1, but statsmodels default is not robust).areg, absorb(fe) → must absorb the same variable, not include as dummies unless no absorb equivalent exists. Flag with # REVIEW: if the approach differs.validate checks. Add _merge diagnostics if the original inspects them.keep if, drop if, filter, and subsetting condition must be translated exactly. Missing value handling differs across languages — explicitly handle this (see body files for language-specific traps).[pw=wt], [aw=wt], [fw=wt] must map to the exact equivalent. Flag if the target language doesn't distinguish weight types.pwcorr, sig → Pearson with p-values, not Spearman.The translated figure must be visually identical to the original. Go through every visual property line by line:
blue stays blue, red stays red. Match the exact color name or hex code.alpha=0.7 → %70 in Stata, alpha = 0.7 in R. Never omit.edgecolors="white", linewidth=0.5, the translation must replicate this (Stata: mlcolor(white) mlwidth(vthin)).ax.grid(True, alpha=0.3), the translation must include grid lines. If there is no grid, the translation must not add one.position(5) ring(0) = lower right inside. Default upper-right → translate to upper-right. Never leave to default if the original specifies a position.ylim, xlim, or custom tick marks, replicate them. If it uses auto-scaling, let the target auto-scale too.figsize=(8, 6) → target equivalent (Stata: xsize(8) ysize(6); R: width = 8, height = 6)If a visual property cannot be exactly replicated, add a # REVIEW: [property] has no exact equivalent in [target language] comment explaining the closest approximation used.
After translation, wrap the script in the project's conventions:
Python target:
import config as cfg for pathscfg.FIGURES / "name.png" for figure outputdpi=300, bbox_inches='tight', plt.close(fig)Stata target:
version 17, clear all, set more offdo "$root/code/stata/config_local.do" for $data_rootlog using "$root/quality_reports/stata_logs/[name].log", replacegraphregion(color(white)) bgcolor(white), width(2400)log close at endR target:
library() calls at tophere::here() for pathsggsave(width = 8, height = 6, dpi = 300)set.seed(42) if stochasticPresent the translation as:
# REVIEW: items and why they were flaggedAfter writing the translated script, run it and check for errors:
python code/py/<script>.pystata -b do code/stata/<script>.do (ALWAYS use the stata wrapper, never call StataSE-64.exe directly — the wrapper auto-moves batch logs to quality_reports/stata_logs/). Then check log for r(Rscript code/R/<script>.RIf it fails, fix only the syntax error (not the logic) and re-run. If the failure is due to a bug in the original, note it in Translation Notes.
testing
Perform adversarial visual audit of Quarto or Beamer slides checking for overflow, font consistency, box fatigue, and layout issues.
testing
Validate bibliography entries against citations in all lecture files. Find missing entries and unused references.
testing
Translate Beamer LaTeX to Quarto RevealJS. Multi-phase workflow with TikZ extraction and QA.
tools
Context and tools for working with Stata — writing .do files, running them in batch mode, and efficiently consulting the bundled PDF documentation.