
Stata Data Cleaning
Clean and transform messy data in Stata with reproducible workflows
Install
npx skills add brycewang-stanford/Auto-Empirical-Research-Skills --skill stata-data-cleaning -g -a claude-code -y- Repository
- brycewang-stanford/Auto-Empirical-Research-Skills4.9k
- Category
- Engineering
- Updated
- 6d ago
- License
- See repository
- Context cost
- Mediumabout 1,743 tokens
- Runs scripts
- No, instructions only
What it does
Clean and transform messy data in Stata with reproducible workflows
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:
- What is the data source? (survey, administrative, API, etc.)
- What is the unit of observation?
- What are the key variables needed for analysis?
- Are there known data quality issues to address?
Step 2: Generate Cleaning Pipeline
Create a Stata do-file that:
- Has a clear header with project info and date
- Sets up the environment (clear all, set memory, log)
- Loads and inspects raw data
- Documents each transformation with comments
- Creates a codebook for the final dataset
Step 3: Follow Best Practices
- Use
assertstatements 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
/*==============================================================================
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
