Stata Data Cleaning logo

Stata Data Cleaning

CommunityPopular
brycewang-stanford
stata-data-cleaning

Clean and transform messy data in Stata with reproducible workflows

Overview

Publisherbrycewang-stanford
RepositoryAuto-Empirical-Research-Skills
Skill namestata-data-cleaning
Stars
3.8K
Forks
479
Bundled files
1
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by brycewang-stanford on GitHub. Read the source before you install it.

Installation

Install the Stata Data Cleaning AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills.git /tmp/Auto-Empirical-Research-Skills
mkdir -p .claude/skills
cp -r /tmp/Auto-Empirical-Research-Skills/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/data/stata-data-cleaning .claude/skills/stata-data-cleaning
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Stata Data Cleaning in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Stata Data Cleaning on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Stata Data Cleaning is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

* Set working directory
cd "/path/to/project"

* Define globals for paths
global raw_data "data/raw"
global clean_data "data/clean"
global output "output"

* ============================================
* 2. LOAD AND INSPECT RAW DATA
* ============================================

use "${raw_data}/raw_survey_data.dta", clear

* Basic inspection
describe
summarize
codebook, compact

* Check for duplicates
duplicates report id_var
duplicates list id_var if _dup > 0

* ============================================
* 3. VARIABLE CLEANING
* ============================================

* --- Rename variables for clarity ---
rename q1 age
rename q2 income_reported
rename q3 education_level

* --- Clean numeric variables ---
* Replace missing value codes with .
mvdecode age income_reported, mv(-99 -88 -77)

* Cap outliers at 99th percentile
qui sum income_reported, detail
replace income_reported = r(p99) if income_reported > r(p99) & !mi(income_reported)

* --- Clean string variables ---
* Standardize state names
replace state = upper(trim(state))
replace state = "NEW YORK" if inlist(state, "NY", "N.Y.", "N Y")

* --- Create categorical variables ---
gen education_cat = .
replace education_cat = 1 if education_level < 12
replace education_cat = 2 if education_level == 12
replace education_cat = 3 if education_level > 12 & education_level <= 16
replace education_cat = 4 if education_level > 16 & !mi(education_level)

label define edu_lbl 1 "Less than HS" 2 "High School" 3 "College" 4 "Graduate"
label values education_cat edu_lbl

* ============================================
* 4. HANDLE MISSING DATA
* ============================================

* Create missing indicator variables
gen mi_income = mi(income_reported)

* Document missingness
tab mi_income

* Count complete cases
egen complete_case = rownonmiss(age income_reported education_cat)
tab complete_case

* ============================================
* 5. CREATE DERIVED VARIABLES
* ============================================

* Age groups
gen age_group = .
replace age_group = 1 if age >= 18 & age < 30
replace age_group = 2 if age >= 30 & age < 50
replace age_group = 3 if age >= 50 & age < 65
replace age_group = 4 if age >= 65 & !mi(age)

label define age_lbl 1 "18-29" 2 "30-49" 3 "50-64" 4 "65+"
label values age_group age_lbl

* Log income
gen log_income = ln(income_reported + 1)

* ============================================
* 6. DATA VALIDATION
* ============================================

* Assert expected ranges
assert age >= 18 & age <= 120 if !mi(age)
assert income_reported >= 0 if !mi(income_reported)

* Check variable types
assert !mi(id_var)
isid id_var  // Verify unique identifier

* ============================================
* 7. LABEL VARIABLES
* ============================================

label variable age "Age in years"
label variable income_reported "Annual income (USD)"
label variable education_cat "Education category"
label variable log_income "Log of annual income"
label variable mi_income "Missing income indicator"

* ============================================
* 8. FINAL CHECKS AND SAVE
* ============================================

* Keep relevant variables
keep id_var age age_group income_reported log_income ///
     education_cat mi_income state year

* Order variables logically
order id_var year state age age_group income_reported ///
      log_income education_cat mi_income

* Compress to minimize file size
compress

* Save cleaned data
save "${clean_data}/cleaned_analysis_data.dta", replace

* Create codebook
codebook, compact

* Close log
log close

* ============================================
* END OF FILE
* ============================================

Requirements

Software

  • Stata 15+ (some commands require newer versions)

Recommended User-Written Commands

stata
ssc install unique     // For unique value checking
ssc install mdesc      // For missing data patterns
ssc install labutil    // For label manipulation

Best Practices

  1. Always start with clear all to ensure clean environment
  2. Use log files to document all transformations
  3. Comment extensively - explain WHY, not just WHAT
  4. Use assert statements to catch data errors early
  5. Create a data dictionary alongside your cleaned data
  6. Version your do-files and datasets

Common Pitfalls

  • ❌ Not checking for duplicates before merging
  • ❌ Forgetting to handle missing value codes (-99, -88, etc.)
  • ❌ Not labeling variables and values
  • ❌ Overwriting raw data files
  • ❌ Not documenting data transformations

References

Changelog

v1.0.0

  • Initial release with comprehensive cleaning template

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Stata Data Cleaning AI skill do?

Clean and transform messy data in Stata with reproducible workflows

Why use Stata Data Cleaning on TypingMind?

Because you install it once and use it with any model. Stata Data Cleaning is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Stata Data Cleaning in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/tree/main/skills/09-meleantonio-awesome-econ-ai-stuff/_skills/data/stata-data-cleaning. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Stata Data Cleaning?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Stata Data Cleaning?

As many as you like. As long as a model supports skills, you can use Stata Data Cleaning with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Stata Data Cleaning AI skill free?

It is published on GitHub by brycewang-stanford. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇