Cross language check

From flonat/flonat-research · View interactive version

Cross language check is an AI agent skill from the GitHub repository flonat/flonat-research. Replicate a quantitative analysis in a second language (R↔Python↔Stata↔Julia) and compare outputs for implementation errors. Use when an existing empirical result needs independent cross-language verification. Not for reviewing one implementation in place; use $code-suite.

How to use this skill

Skill file

Cross-Language Replication Check

Level 1 of the verification hierarchy: same specification → same estimate across languages. If two independent implementations disagree, at least one has a bug.

Output Path

Per rules/review-artefact-routing.md (auto-loads in research projects (path-scoped to paper-*/ and paper/)):

When to Use

When NOT to Use

Workflow

Phase 1: Parse Source Script

  1. Read the source script — identify language, packages, estimation calls
  2. Extract the specification:
  1. Identify key outputs — point estimates, standard errors, p-values, confidence intervals, N
  2. Flag untranslatable elements — language-specific features that may need adaptation (e.g., R formula syntax, Stata factor variables, Python sklearn pipelines)

Phase 2: Choose Target Language

If --target is specified, use that. Otherwise:

| Source | Default target | Rationale |

|--------|---------------|-----------|

| R | Python | Widest package overlap |

| Python | R | Strongest econometrics ecosystem |

| Stata | R | Both strong on panel/causal methods |

| Julia | Python | Closest syntax mapping |

Ask the user to confirm if the default seems wrong for the specific analysis.

Phase 3: Translate

Write the replication script to code/replication/ (or src/replication/):

code/replication/{original_name}_{target_lang}.{ext}

Translation rules:

  1. Mirror the specification exactly — same formula, same controls, same sample restrictions
  2. Use equivalent packages (see shared/multi-language-conventions.md for mappings)
  3. Match output format — both scripts should produce a CSV with columns: estimate, se, pvalue, ci_lower, ci_upper, n, model_label
  4. Document every adaptation — comment blocks explaining where the translation required judgment calls
  5. Use the same data file — both scripts read from the same cleaned dataset

Phase 4: Run Both & Compare

  1. Run the source script, capture output CSV
  2. Run the replication script, capture output CSV
  3. Comparison thresholds:

| Metric | Threshold | Verdict |

|--------|-----------|---------|

| Point estimates | Differ by < 0.1% | PASS |

| Point estimates | Differ by 0.1–1% | WARN — likely rounding or optimizer differences |

| Point estimates | Differ by > 1% | FAIL — investigate |

| Standard errors | Differ by < 1% | PASS |

| Standard errors | Differ by 1–5% | WARN — check SE type (robust, clustered, HC1 vs HC3) |

| Standard errors | Differ by > 5% | FAIL — likely different SE computation |

| Sample size N | Must be identical | FAIL if different — data filtering diverged |

  1. Generate comparison table saved to code/replication/comparison.md:
| Model | Estimate (source) | Estimate (replica) | Diff (%) | SE (source) | SE (replica) | Diff (%) | N match | Verdict |

Phase 5: Diagnose Discrepancies

If any FAIL or WARN:

  1. Check N first — if sample sizes differ, the data pipeline diverged (most common source of bugs)
  2. Check SE type — HC1 vs HC3 vs clustered vs bootstrap defaults differ across languages
  3. Check optimizer — MLE/GLM may converge to different optima with different starting values
  4. Check missing value handling — NA dropping rules differ (R drops per-variable, Stata drops listwise, Python varies)
  5. Check factor variable encoding — reference category defaults differ across languages

Report the root cause, not just the symptom.

Phase 6: Report

Save to code/replication/cross-language-report.md:

# Cross-Language Replication Report

**Source:** {source_path} ({source_language})
**Replica:** {replica_path} ({target_language})
**Date:** {date}

## Summary
- Models checked: N
- PASS: N | WARN: N | FAIL: N

## Comparison Table
[from Phase 4]

## Discrepancies
[from Phase 5, if any]

## Verdict
[REPLICATED | REPLICATED WITH NOTES | FAILED — action required]

Common Package Mappings

| Task | R | Python | Stata | Julia |

|------|---|--------|-------|-------|

| OLS + FE | fixest::feols | linearmodels.PanelOLS | reghdfe | FixedEffectModels.reg |

| IV | fixest::feols (iv syntax) | linearmodels.IV2SLS | ivregress 2sls | FixedEffectModels.reg |

| DiD | did::att_gt | differences | csdid | — |

| Clustered SE | vcov = ~cluster | cov_type='clustered' | vce(cluster var) | Vcov.cluster(:var) |

| Logit/Probit | glm(family=binomial) | statsmodels.Logit | logit | GLM.jl |

Log to REVIEW-STATE.md (final step)

Write the comparison report to reviews/<scope>/cross-language-check/<YYYY-MM-DD-HHMM>.md (where <scope> is the paper slug for paper-level checks or _project for project-level checks; mkdir -p reviews/<scope>/cross-language-check/ first). Then append a row to the project's REVIEW-STATE.md:

bash <skills-root>/_shared/review-state-log.sh \
  --check cross-language-check \
  --paper "<paper-{venue} dir, or — for project-level cross-language checks>" \
  --verdict "<MATCH|DIVERGENCE>" \
  --score "<pass-count>/<total-comparisons>" \
  --open-issues "<fail-count>/<total-comparisons>" \
  --report "reviews/<scope>/cross-language-check/<YYYY-MM-DD-HHMM>.md" \
  --notes "<one-line: e.g. 'all match within tol'; or 'IV SE differs in §4'>" \
  [--trigger "pre-submission-report|review-cluster"]

Schema: the installed shared resource shared/review-state-schema.md.

Cross-References

| Resource | When read |

|----------|-----------|

| shared/multi-language-conventions.md | Phase 3 (language-specific style) |

| multi-perspective/references/computational-many-analysts.md | Context (verification hierarchy) |

| the code-review agent | Phase 6 (optionally review both scripts) |

| replication-package skill | After (include both scripts in replication materials) |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.