# Stata Data Cleaning

Clean and transform messy data in Stata with reproducible workflows

- Repository: https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills (4869 stars)
- Category: Engineering
- License: see repository
- Last updated: 2026-10-30
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata-data-cleaning -g -a claude-code -y`
Codex: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata-data-cleaning -g -a codex -y`
Cursor: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata-data-cleaning -g -a cursor -y`
Gemini CLI: `npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata-data-cleaning -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add brycewang-stanford/Auto-Empirical-Research-Skills`

## Description

Clean and transform messy data in Stata with reproducible workflows

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Stata Data Cleaning

## Purpose

This skill helps economists clean, transform, and prepare datasets for analysis in Stata. It emphasizes reproducibility, proper documentation, and handling common data quality issues found in economic research.

## When to Use

- Cleaning raw survey or administrative data
- Merging multiple data sources
- Handling missing values, duplicates, and outliers
- Creating analysis-ready panel datasets
- Documenting data transformations for replication

## Instructions

### Step 1: Understand the Data

Before generating code, ask the user:
1. What is the data source? (survey, administrative, API, etc.)
2. What is the unit of observation?
3. What are the key variables needed for analysis?
4. Are there known data quality issues to address?

### Step 2: Generate Cleaning Pipeline

Create a Stata do-file that:

1. **Has a clear header** with project info and date
2. **Sets up the environment** (clear all, set memory, log)
3. **Loads and inspects raw data**
4. **Documents each transformation** with comments
5. **Creates a codebook** for the final dataset

### Step 3: Follow Best Practices

- Use `assert` statements to verify data integrity
- Create labeled variables with `label variable`
- Use value labels for categorical variables
- Generate a log file for reproducibility
- Save intermediate files when appropriate

## Example Output

```stata
/*==============================================================================
    Project:    Economic Analysis Data Cleaning
    Author:     [Your Name]
    Date:       [Date]
    Purpose:    Clean raw survey data for regression analysis
    Input:      raw_survey_data.dta
    Output:     cleaned_analysis_data.dta
==============================================================================*/

* ============================================
* 1. SETUP
* ============================================

clear all
set more off
cap log close
log using "logs/data_cleaning_`c(current_date)'.log", replace

The rest: https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/blob/HEAD/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/data/stata-data-cleaning/SKILL.md
