Statistical Interpretation across Stata, R & Python

Moderate · Data & Analysis track · ~35 min hands-on + readings and quiz

← Back to the Data & Analysis track

Read output, translate between languages, and sanity-check what AI tells you.

What you’ll be able to do

  • Have AI explain model output in plain language
  • Translate a model or command between Stata, R, and Python
  • Sanity-check estimates and the assumptions behind them

Overview

AI can explain output, translate a Stata command into R or Python, and suggest diagnostics. It can also be confidently wrong about methods — treat its statistical claims as drafts to verify against a text or a statistician.

Interpretation and assumptions are exactly where your expertise matters most; that part doesn’t transfer to the tool.

Practice activities

Activity 1 · Moderate — Translate a model across Stata, R, and Python

Time ~20 min · Tools ChatGPT Edu + Stata and/or R/Python

Goal. Move a model between languages and confirm the translation is faithful.

Setup. Download the Philadelphia Crash Data 2020–2024 (CSV). Key columns you’ll use:

Column name Description Values
FATAL_COUNT Number of fatalities 0, 1, 2, … (create a binary indicator: 1 if > 0)
SPEED_RELATED Was speeding a factor? 0 = No, 1 = Yes
INTERSECT_TYPE Intersection type 0 = Non-intersection, 1–9 = various intersection types (recode to binary: 0 vs. any)
ILLUMINATION Lighting conditions 1 = Daylight, 2 = Dark (no street lights), 3 = Dark (street lights), 4 = Dusk, 5 = Dawn, 8 = Other, 9 = Unknown (recode to binary: dark vs. light)
PEDESTRIAN Pedestrian involved? 0 = No, 1 = Yes
BICYCLE Bicycle involved? 0 = No, 1 = Yes
CRASH_MONTH Month of crash 1–12
DAY_OF_WEEK Day of week 1 = Sunday … 7 = Saturday

Outcome: a fatal-crash indicator (FATAL_COUNT > 0). Predictors: SPEED_RELATED, intersection (binary from INTERSECT_TYPE), and a dark/light indicator (binary from ILLUMINATION). Optionally restrict to pedestrian-involved crashes (PEDESTRIAN == 1).

Steps.

  1. Start in your home language (Stata, if that’s yours):

    Write Stata code for a logistic regression of a fatal-crash indicator on speeding, intersection, and a light/dark indicator using this Philadelphia crash data. Then give the exact equivalent in R (glm) and Python (statsmodels), and interpret the output in plain language.

  2. Run at least two of the three.

  3. Compare:

    The R and Stata results should match. Confirm the coefficients, odds ratios, and sample sizes are the same; if they differ, explain why.

Expected result. Matching estimates across languages, plus an odds-ratio interpretation.

Check your work. Ns and coefficients should match across languages (only tiny differences from default options).

Common pitfalls. Different default reference categories or NA handling cause mismatches — check those first. Treat any statistical claim from AI as a draft to verify.

Stretch (optional). Ask which model assumptions matter most here and how to check each.

Activity 2 · Moderate — Interrogate the output

Time ~15 min · Tools ChatGPT Edu + R or Stata

Goal. Decide what the model actually supports — and what it doesn’t.

Setup. Use the model you fit in Activity 1.

Steps.

  1. Paste the output:

    Here is my logistic regression output. What assumptions should I check, and how (in R or Stata)? Flag any sign of separation, sparse cells, or multicollinearity.

  2. Run the suggested checks.

  3. Ask for a careful interpretation:

    Write a two-sentence, accurate interpretation of the speeding odds ratio for a non-statistical audience — without overclaiming causality.

Expected result. A list of checks you ran, plus an honest, non-causal interpretation.

Check your work. Confirm every claim against the output; reject anything the data don’t support.

Common pitfalls. AI often slips into causal language (“speeding causes…”). This is observational data — keep it associational.

Stretch (optional). Ask AI to name the single biggest threat to validity in this analysis.

Activity 3 · Moderate — Translate and verify with Claude Code

Time ~25 min · Tools Claude Code

Goal. Have an agent translate the same logistic regression across Stata, R, and Python — and actually run the R and Python versions to prove the results match, instead of you comparing outputs by hand.

Setup. Download the Philadelphia Crash Data 2020–2024 CSV into a working folder and open a terminal there. You’ll need Claude Code installed plus R and/or Python on your machine — Claude Code can run whatever you have. One honest caveat: it can write the Stata .do file, but it can’t run Stata unless you have a licensed copy with command-line access configured, so the Stata version stays code-on-paper here.

Steps.

  1. Start Claude Code in the folder with the CSV and give it the full task in one prompt: > In this folder is crashes.csv, Philadelphia crash data. Build a logistic regression predicting a fatal-crash indicator (FATAL_COUNT > 0) from SPEED_RELATED, an intersection binary derived from INTERSECT_TYPE, and a dark/light binary derived from ILLUMINATION. Write three scripts: Stata (.do), R (glm), and Python (statsmodels). Use identical variable coding and reference categories in all three.
  2. Then have it verify rather than just generate: > Run the R and Python scripts. Report the N, coefficients, and odds ratios from each side by side, and tell me explicitly whether they match. Don’t tell me the code “should” be equivalent — show me the actual output.
  3. If it reports a mismatch (common culprits: R and Python defaulting to different reference categories, or dropping missing rows differently), ask it to diagnose and fix: > The Ns differ. Figure out whether it’s NA handling, factor coding, or how the binaries were derived, fix it so both scripts use the same rules, and re-run both to confirm.

Expected result. Three scripts on disk, plus a side-by-side comparison where the agent has run the R and Python versions itself and confirmed identical Ns, coefficients, and odds ratios — with any discrepancy diagnosed and resolved, not eyeballed. The Stata script should mirror the same coding, verified by you in Stata if you have it.

Check your work. Open the scripts and read the variable derivations yourself — did it code “dark” and “intersection” the way you intended, and does the missing-data rule make sense for these variables? The agent can prove the two scripts agree with each other; only you can confirm they both answer the right question. If you have Stata, run the .do file and check it matches too.

Common pitfalls. Agreement between R and Python is not the same as correctness — both scripts can share the same wrong recoding, which is exactly why you read the derivation code. And the standing rule: Claude Code is not Drexel-supported and is approved for Low Risk Data only — fine for this public crash CSV, not for anything with identifiable or restricted data.

Stretch (optional). Ask Claude Code to add a robustness check to both scripts — for example, refit treating ILLUMINATION as a multi-category factor instead of a binary — and report whether the SPEED_RELATED odds ratio holds up.

Check your readiness

Answer these, then check — your score suggests whether to dive in or skim the readings first.

Useful resources