Research Code Audit Protocol
Overview
This is a two-phase audit. Phase 1 is strictly read-only — do not
execute any code. Phase 2 only proceeds with explicit user approval.
This separation matters because research code often touches licensed
datasets (WRDS, CRSP, WellDatabase, PLIDA) that have access restrictions,
and because running code on large datasets without review risks producing
results from buggy pipelines that then get embedded in manuscripts.
Phase 1: Static Review (read-only)
Read the code without executing anything. Produce a structured report
covering the sections below.
1. Data integrity
- Are there checks for duplicates in the panel identifier?
- Are missing values / NAs handled explicitly (not silently dropped)?
- Is the panel balanced or unbalanced, and is this acknowledged?
- Are merges validated? Check:
- Join type (left, inner, full) — is it intentional?
- Many-to-one vs one-to-one — is this documented?
- Post-merge row count check (did the merge inflate observations?)
- Are data filters documented and justified in comments?
- Are there sample selection steps that could introduce bias?
2. Econometric concerns
- Is the identification strategy clearly implemented in the code?
- Are standard errors clustered at the appropriate level?
- Panel data: at minimum, cluster at the unit level
- If iid SEs are used, flag this as likely incorrect
- Are fixed effects consistent with the stated research design?
- For Difference-in-Differences:
- Is the parallel trends assumption testable with this data?
- Is it tested (e.g., event study plot, pre-treatment coefficients)?
- For staggered adoption: is a robust estimator used (Sun & Abraham,
Callaway & Sant'Anna, etc.) or is vanilla TWFE flagged as problematic?
- For Instrumental Variables:
- Is the first stage reported?
- Is the first-stage F-statistic checked (rule of thumb: F > 10)?
- Is the exclusion restriction discussed in comments?
- Are there potential bad controls (Angrist & Pischke)?
- Variables that are themselves affected by treatment
- Post-treatment outcomes included as controls
- Is winsorisation or trimming applied? At what level? Is it justified?
3. Reproducibility
- Is a random seed set where randomisation is used?
- Are file paths relative to the project root (not absolute)?
- Are package versions recorded (
renv.lock, sessionInfo(), or equivalent)?
- Can the pipeline run end-to-end from raw data to final output?
- Is there a clear execution order (numbered scripts, makefile, or README)?
- Are intermediate outputs saved so individual scripts can be re-run?
4. Code quality
- Redundant computations or copy-paste patterns that should be functions
- Hardcoded values that should be parameters (e.g., winsorisation cutoffs,
sample date ranges, variable names repeated as strings)
- Missing comments on non-obvious transformations
- Variable names that are ambiguous or misleading
- Scripts that are excessively long (>300 lines) and should be split
Phase 2: Execution checks (requires explicit user approval)
Do NOT proceed to this phase unless the user explicitly says something like
"go ahead and run it", "you can execute", or "test it."
When approved:
- Run on a small sample or synthetic data first — never on the full
dataset as a first step
- Verify output dimensions match expectations
- Check that coefficient magnitudes are reasonable (not astronomically
large or exactly zero when they shouldn't be)
- Compare against any baseline results the user provides
- Check for convergence warnings or estimation issues in the log
Output format
Present findings as a structured report with severity levels:
🔴 Critical: Results may be wrong. Must fix before interpreting output.
Examples: wrong clustering, bad merge inflating observations, post-treatment
controls, missing fixed effects.
🟡 Warning: Potential issue worth investigating. May or may not affect
conclusions. Examples: no duplicate check, missing parallel trends test,
hardcoded sample restrictions.
🟢 Note: Suggestion for improvement. Won't affect results but improves
code quality or reproducibility. Examples: absolute file paths, missing
comments, inefficient code patterns.
End every audit with a Recommendations section listing concrete,
actionable fixes ordered by severity. Each recommendation should reference
the specific line(s) of code involved.
1---2name: code-audit3description: Two-phase code audit workflow for empirical research scripts. Use this skill when the user asks to review, audit, check, validate, or verify R or Python research code — especially code that processes licensed or sensitive data (WRDS, CRSP, WellDatabase, PLIDA). Also use when the user says "check my code", "review this script", "does this look right", or "audit my analysis."4---56# Research Code Audit Protocol78## Overview910This is a **two-phase audit**. Phase 1 is strictly read-only — do not11execute any code. Phase 2 only proceeds with explicit user approval.1213This separation matters because research code often touches licensed14datasets (WRDS, CRSP, WellDatabase, PLIDA) that have access restrictions,15and because running code on large datasets without review risks producing16results from buggy pipelines that then get embedded in manuscripts.1718---1920## Phase 1: Static Review (read-only)2122Read the code without executing anything. Produce a structured report23covering the sections below.2425### 1. Data integrity2627- Are there checks for duplicates in the panel identifier?28- Are missing values / NAs handled explicitly (not silently dropped)?29- Is the panel balanced or unbalanced, and is this acknowledged?30- Are merges validated? Check:31 - Join type (left, inner, full) — is it intentional?32 - Many-to-one vs one-to-one — is this documented?33 - Post-merge row count check (did the merge inflate observations?)34- Are data filters documented and justified in comments?35- Are there sample selection steps that could introduce bias?3637### 2. Econometric concerns3839- Is the identification strategy clearly implemented in the code?40- Are standard errors clustered at the appropriate level?41 - Panel data: at minimum, cluster at the unit level42 - If iid SEs are used, flag this as likely incorrect43- Are fixed effects consistent with the stated research design?44- For Difference-in-Differences:45 - Is the parallel trends assumption testable with this data?46 - Is it tested (e.g., event study plot, pre-treatment coefficients)?47 - For staggered adoption: is a robust estimator used (Sun & Abraham,48 Callaway & Sant'Anna, etc.) or is vanilla TWFE flagged as problematic?49- For Instrumental Variables:50 - Is the first stage reported?51 - Is the first-stage F-statistic checked (rule of thumb: F > 10)?52 - Is the exclusion restriction discussed in comments?53- Are there potential bad controls (Angrist & Pischke)?54 - Variables that are themselves affected by treatment55 - Post-treatment outcomes included as controls56- Is winsorisation or trimming applied? At what level? Is it justified?5758### 3. Reproducibility5960- Is a random seed set where randomisation is used?61- Are file paths relative to the project root (not absolute)?62- Are package versions recorded (`renv.lock`, `sessionInfo()`, or equivalent)?63- Can the pipeline run end-to-end from raw data to final output?64- Is there a clear execution order (numbered scripts, makefile, or README)?65- Are intermediate outputs saved so individual scripts can be re-run?6667### 4. Code quality6869- Redundant computations or copy-paste patterns that should be functions70- Hardcoded values that should be parameters (e.g., winsorisation cutoffs,71 sample date ranges, variable names repeated as strings)72- Missing comments on non-obvious transformations73- Variable names that are ambiguous or misleading74- Scripts that are excessively long (>300 lines) and should be split7576---7778## Phase 2: Execution checks (requires explicit user approval)7980Do NOT proceed to this phase unless the user explicitly says something like81"go ahead and run it", "you can execute", or "test it."8283When approved:841. Run on a **small sample or synthetic data first** — never on the full85 dataset as a first step862. Verify output dimensions match expectations873. Check that coefficient magnitudes are reasonable (not astronomically88 large or exactly zero when they shouldn't be)894. Compare against any baseline results the user provides905. Check for convergence warnings or estimation issues in the log9192---9394## Output format9596Present findings as a structured report with severity levels:9798- 🔴 **Critical**: Results may be wrong. Must fix before interpreting output.99 Examples: wrong clustering, bad merge inflating observations, post-treatment100 controls, missing fixed effects.101102- 🟡 **Warning**: Potential issue worth investigating. May or may not affect103 conclusions. Examples: no duplicate check, missing parallel trends test,104 hardcoded sample restrictions.105106- 🟢 **Note**: Suggestion for improvement. Won't affect results but improves107 code quality or reproducibility. Examples: absolute file paths, missing108 comments, inefficient code patterns.109110End every audit with a **Recommendations** section listing concrete,111actionable fixes ordered by severity. Each recommendation should reference112the specific line(s) of code involved.