Data Analysis Pipeline
Generate, execute, and verify analysis scripts across R, Python, Stata, and Julia.
Modes
| Mode |
What it does |
Phases |
| EDA |
Exploratory data analysis only |
1–2 |
| Estimation |
Estimation + publication output (requires locked design) |
1, 3–4 |
| Full |
Complete pipeline |
1–5 |
Default: Full. Detect mode from user request or ask if ambiguous.
When to Use
- "Analyse this data" / "Run EDA on this CSV" / "Estimate the model"
- "Generate results tables" / "Create publication figures"
- Any task requiring data → script → output pipeline
When NOT to Use
- Experimental design or power analysis →
experiment-design
- Generating synthetic data for testing →
synthetic-data
- Auditing identification strategy →
causal-design
- Proofreading or compiling the paper →
proofread, latex
Shared References
- Method probing questions:
shared/method-probing-questions.md — ask before running any analysis
- Validation tiers:
shared/validation-tiers.md — declare tier before examining results
- Escalation protocol:
shared/escalation-protocol.md — escalate when methodology answers are vague
- Distribution diagnostics:
shared/distribution-diagnostics.md — mandatory DV checks before model selection
- Engagement-stratified sampling:
shared/engagement-stratified-sampling.md — stratify by engagement tiers for social media data
- Inter-coder reliability:
shared/intercoder-reliability.md — per-category reliability for content analysis and LLM annotation
Workflow
Phase 1: Setup
- Detect project structure: Read
CLAUDE.md, check for data/, code/, paper/ directories.
- Detect language: Check existing scripts, user preference, or ask. Read
shared/multi-language-conventions.md for the chosen language's conventions.
- Locate data: Find datasets in
data/raw/ or data/processed/. Never modify data/raw/ (per data-sensitivity rule). For social-media datasets, follow shared/engagement-stratified-sampling.md when constructing analysis samples.
- Confirm validation tier per
shared/validation-tiers.md. Tier dictates claim-strength language allowed in Phase 4 outputs and how strict the locked-design gate (step 5) is enforced.
- Check for locked design: Look for analysis plan in
log/plans/, .context/project-recap.md, or MEMORY.md estimand registry. If running Estimation or Full mode and no design exists, stop and warn: "No locked research design found. Run experiment-design or causal-design first, or confirm the specification before proceeding." Use shared/method-probing-questions.md to probe gaps if the user pushes back on the gate.
Phase 2: Exploratory Data Analysis
Generate and execute an EDA script that produces:
- Data overview: dimensions, types, missingness summary
- Univariate distributions: histograms/density for continuous, bar charts for categorical
- Bivariate relationships: correlation matrix, key scatterplots, cross-tabulations
- Outlier detection: box plots, IQR-based flags
- Distribution diagnostics (mandatory): run
distribution_diagnostics() from shared/distribution-diagnostics.md on every DV and key IVs. Report skewness, zero proportion, overdispersion, and model recommendation. Flag if OLS is inappropriate.
- Balance tables (if treatment variable identified): pre-treatment covariate balance
Output routing:
- Exploratory figures →
output/figures/ (not paper/figures/)
- Summary statistics →
output/tables/ as .csv
- EDA script →
code/01_eda.R (or .py/.do/.jl)
EDA mode stops here.
Phase 3: Estimation
Gate check: Verify the research design is locked before proceeding. The specification (estimand, identifying assumptions, main model) must be documented. This enforces the design-before-results rule. If the user resists the gate, follow shared/escalation-protocol.md — escalate rather than accommodate. For analyses involving human or LLM coding (content analysis, annotation), require per-category reliability per shared/intercoder-reliability.md before estimation.
Generate estimation script(s) covering:
- Main specification — as defined in the locked design
- Robustness checks — pre-committed alternatives (different SEs, controls, subsamples)
- Diagnostics — specification-appropriate tests (first-stage F for IV, parallel trends for DiD, bandwidth sensitivity for RDD)
Read references/estimation-recipes.md for language-specific estimation patterns.
Output:
- Estimation script →
code/02_estimation.R (or equivalent)
- Coefficient estimates →
output/results/ as .rds/.pkl/.dta for downstream table generation
Phase 4: Publication Output
Generate publication-ready tables and figures. Read shared/publication-output.md for format standards and references/table-formatting.md for language-specific recipes.
- Main results table — booktabs three-line format, exported as
.tex to paper/tables/
- Robustness tables — same format, appendix naming convention
- Publication figures — coefficient plots, event study plots, mechanism figures →
paper/figures/ as PDF
- Inline statistics — export
\newcommand definitions for key numbers referenced in text
Critical rule: All numbers in .tex files must come from generated files via \input{}. Never hard-code results (per no-hardcoded-results rule). Scripts in code/, outputs in paper/ (per overleaf-separation rule).
Output script → code/03_tables_figures.R (or equivalent)
Phase 5: Save & Review
- Verify outputs exist: Check all expected files in
paper/tables/ and paper/figures/
- Run the
code-review agent on all generated scripts (auto-invoke via skill-routing mechanism)
- Log the analysis: Record what was done, which scripts were created, which outputs were generated
- Suggest next steps: compilation with
latex, or additional analyses
Script Structure
Every generated script follows this header template:
# ============================================================
# Script: [filename]
# Purpose: [one-line description]
# Inputs: [list of input files]
# Outputs: [list of output files]
# Dependencies: [packages used]
# Author: [from git config]
# Date: [today]
# ============================================================
Cross-References
| Resource |
When read |
shared/multi-language-conventions.md |
Phase 1 (language setup) |
shared/publication-output.md |
Phase 4 (table/figure format) |
references/estimation-recipes.md |
Phase 3 (estimation code patterns) |
references/econ-visualisation.md |
Phase 2 & 4 (economics figure/table conventions) |
references/table-formatting.md |
Phase 4 (language-specific table export) |
references/language-conventions.md |
Phase 1 (additional language notes) |
design-before-results rule |
Phase 3 gate check |
data-sensitivity rule |
Phase 1 (data access) |
no-hardcoded-results rule |
Phase 4 (output routing) |
overleaf-separation rule |
Phase 4 (file placement) |
the code-review agent |
Phase 5 (auto-invoked) |
experiment-design skill |
Suggested if no design exists |
causal-design skill |
Suggested if no design exists |
econ-plots skill |
Economics-specific figures |
r-econometrics skill |
R-specific estimation |
econ-data skill |
Data download from public APIs |
1---2name: data-analysis3description: "Deliver an end-to-end analysis pipeline: EDA, estimation, or publication output. Use when the user requests an end-to-end analysis pipeline: EDA, estimation, or publication output."4allowed-tools: Bash(uv*, Rscript*, R*, stata*, julia*, mkdir*, ls*, cp*), Read, Write, Edit, Glob, Grep, AskUserQuestion, Skill5argument-hint: "[data-path or project-path] [--mode eda|estimation|full]"6agent-dependencies: [code-review]7skill-dependencies: [experiment-design]8---910# Data Analysis Pipeline1112> Generate, execute, and verify analysis scripts across R, Python, Stata, and Julia.1314## Modes1516| Mode | What it does | Phases |17|------|-------------|--------|18| **EDA** | Exploratory data analysis only | 1–2 |19| **Estimation** | Estimation + publication output (requires locked design) | 1, 3–4 |20| **Full** | Complete pipeline | 1–5 |2122Default: **Full**. Detect mode from user request or ask if ambiguous.2324## When to Use2526- "Analyse this data" / "Run EDA on this CSV" / "Estimate the model"27- "Generate results tables" / "Create publication figures"28- Any task requiring data → script → output pipeline2930## When NOT to Use3132- Experimental design or power analysis → `experiment-design`33- Generating synthetic data for testing → `synthetic-data`34- Auditing identification strategy → `causal-design`35- Proofreading or compiling the paper → `proofread`, `latex`3637## Shared References3839- Method probing questions: `shared/method-probing-questions.md` — ask before running any analysis40- Validation tiers: `shared/validation-tiers.md` — declare tier before examining results41- Escalation protocol: `shared/escalation-protocol.md` — escalate when methodology answers are vague42- Distribution diagnostics: `shared/distribution-diagnostics.md` — mandatory DV checks before model selection43- Engagement-stratified sampling: `shared/engagement-stratified-sampling.md` — stratify by engagement tiers for social media data44- Inter-coder reliability: `shared/intercoder-reliability.md` — per-category reliability for content analysis and LLM annotation4546## Workflow4748### Phase 1: Setup49501. **Detect project structure:** Read `CLAUDE.md`, check for `data/`, `code/`, `paper/` directories.512. **Detect language:** Check existing scripts, user preference, or ask. Read `shared/multi-language-conventions.md` for the chosen language's conventions.523. **Locate data:** Find datasets in `data/raw/` or `data/processed/`. **Never modify `data/raw/`** (per `data-sensitivity` rule). For social-media datasets, follow [`shared/engagement-stratified-sampling.md`](../shared/engagement-stratified-sampling.md) when constructing analysis samples.534. **Confirm validation tier** per [`shared/validation-tiers.md`](../shared/validation-tiers.md). Tier dictates claim-strength language allowed in Phase 4 outputs and how strict the locked-design gate (step 5) is enforced.545. **Check for locked design:** Look for analysis plan in `log/plans/`, `.context/project-recap.md`, or `MEMORY.md` estimand registry. If running Estimation or Full mode and no design exists, **stop and warn:** "No locked research design found. Run `experiment-design` or `causal-design` first, or confirm the specification before proceeding." Use [`shared/method-probing-questions.md`](../shared/method-probing-questions.md) to probe gaps if the user pushes back on the gate.5556### Phase 2: Exploratory Data Analysis5758Generate and execute an EDA script that produces:59601. **Data overview:** dimensions, types, missingness summary612. **Univariate distributions:** histograms/density for continuous, bar charts for categorical623. **Bivariate relationships:** correlation matrix, key scatterplots, cross-tabulations634. **Outlier detection:** box plots, IQR-based flags645. **Distribution diagnostics** (mandatory): run `distribution_diagnostics()` from `shared/distribution-diagnostics.md` on every DV and key IVs. Report skewness, zero proportion, overdispersion, and model recommendation. Flag if OLS is inappropriate.656. **Balance tables** (if treatment variable identified): pre-treatment covariate balance6667**Output routing:**68- Exploratory figures → `output/figures/` (not `paper/figures/`)69- Summary statistics → `output/tables/` as `.csv`70- EDA script → `code/01_eda.R` (or `.py`/`.do`/`.jl`)7172**EDA mode stops here.**7374### Phase 3: Estimation7576**Gate check:** Verify the research design is locked before proceeding. The specification (estimand, identifying assumptions, main model) must be documented. This enforces the `design-before-results` rule. If the user resists the gate, follow [`shared/escalation-protocol.md`](../shared/escalation-protocol.md) — escalate rather than accommodate. For analyses involving human or LLM coding (content analysis, annotation), require per-category reliability per [`shared/intercoder-reliability.md`](../shared/intercoder-reliability.md) before estimation.7778Generate estimation script(s) covering:79801. **Main specification** — as defined in the locked design812. **Robustness checks** — pre-committed alternatives (different SEs, controls, subsamples)823. **Diagnostics** — specification-appropriate tests (first-stage F for IV, parallel trends for DiD, bandwidth sensitivity for RDD)8384Read `references/estimation-recipes.md` for language-specific estimation patterns.8586**Output:**87- Estimation script → `code/02_estimation.R` (or equivalent)88- Coefficient estimates → `output/results/` as `.rds`/`.pkl`/`.dta` for downstream table generation8990### Phase 4: Publication Output9192Generate publication-ready tables and figures. Read `shared/publication-output.md` for format standards and `references/table-formatting.md` for language-specific recipes.93941. **Main results table** — booktabs three-line format, exported as `.tex` to `paper/tables/`952. **Robustness tables** — same format, appendix naming convention963. **Publication figures** — coefficient plots, event study plots, mechanism figures → `paper/figures/` as PDF974. **Inline statistics** — export `\newcommand` definitions for key numbers referenced in text9899**Critical rule:** All numbers in `.tex` files must come from generated files via `\input{}`. **Never hard-code results** (per `no-hardcoded-results` rule). Scripts in `code/`, outputs in `paper/` (per `overleaf-separation` rule).100101**Output script** → `code/03_tables_figures.R` (or equivalent)102103### Phase 5: Save & Review1041051. **Verify outputs exist:** Check all expected files in `paper/tables/` and `paper/figures/`1062. **Run the `code-review` agent** on all generated scripts (auto-invoke via skill-routing mechanism)1073. **Log the analysis:** Record what was done, which scripts were created, which outputs were generated1084. **Suggest next steps:** compilation with `latex`, or additional analyses109110## Script Structure111112Every generated script follows this header template:113114```115# ============================================================116# Script: [filename]117# Purpose: [one-line description]118# Inputs: [list of input files]119# Outputs: [list of output files]120# Dependencies: [packages used]121# Author: [from git config]122# Date: [today]123# ============================================================124```125126## Cross-References127128| Resource | When read |129|----------|-----------|130| `shared/multi-language-conventions.md` | Phase 1 (language setup) |131| `shared/publication-output.md` | Phase 4 (table/figure format) |132| `references/estimation-recipes.md` | Phase 3 (estimation code patterns) |133| `references/econ-visualisation.md` | Phase 2 & 4 (economics figure/table conventions) |134| `references/table-formatting.md` | Phase 4 (language-specific table export) |135| `references/language-conventions.md` | Phase 1 (additional language notes) |136| `design-before-results` rule | Phase 3 gate check |137| `data-sensitivity` rule | Phase 1 (data access) |138| `no-hardcoded-results` rule | Phase 4 (output routing) |139| `overleaf-separation` rule | Phase 4 (file placement) |140| the `code-review` agent | Phase 5 (auto-invoked) |141| `experiment-design` skill | Suggested if no design exists |142| `causal-design` skill | Suggested if no design exists |143| `econ-plots` skill | Economics-specific figures |144| `r-econometrics` skill | R-specific estimation |145| `econ-data` skill | Data download from public APIs |