用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills --skill data-cleaning命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | data-cleaning |
| description | Clean and transform messy data for analysis in Python, R, or Stata |
This skill helps economists clean, transform, and prepare datasets for analysis in Python, R, or Stata. It emphasizes reproducibility, proper documentation, and handling common data quality issues found in economic research.
Before generating code, ask the user:
Create a Stata do-file that:
assert statements to verify data integritylabel variable/*==============================================================================
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
* ============================================
ssc install unique // For unique value checking
ssc install mdesc // For missing data patterns
ssc install labutil // For label manipulation
clear all to ensure clean environmentassert statements to catch data errors early"""
Data Cleaning Pipeline (Python / pandas)
=========================================
Input: data/raw/raw_data.csv
Output: data/clean/clean_data.parquet
"""
import pandas as pd
import numpy as np
from pathlib import Path
# --------------------------------------------------
# 1. Load and inspect
# --------------------------------------------------
df = pd.read_csv("data/raw/raw_data.csv")
print(df.dtypes)
print(df.describe())
print(df.isnull().sum()) # missingness report
# Check for duplicates
print(f"Duplicate rows: {df.duplicated().sum()}")
df = df.drop_duplicates()
# --------------------------------------------------
# 2. Rename and standardize column names
# --------------------------------------------------
df.columns = (
df.columns
.str.strip()
.str.lower()
.str.replace(r"\s+", "_", regex=True)
.str.replace(r"[^a-z0-9_]", "", regex=True)
)
# --------------------------------------------------
# 3. Handle missing value codes
# --------------------------------------------------
MISSING_CODES = [-99, -88, -77, 9999]
df.replace(MISSING_CODES, np.nan, inplace=True)
# --------------------------------------------------
df[] = pd.to_numeric(df[], errors=).astype()
df[] = pd.to_numeric(df[], errors=)
col [, ]:
col df.columns:
lo, hi = df[col].quantile([, ])
df[col] = df[col].clip(lo, hi)
df[] = np.log1p(df[])
df[] = df[].isna().astype()
df[].notna().(),
df[].is_unique,
(df[].dropna() >= ).(),
Path().mkdir(parents=, exist_ok=)
df.to_parquet(, index=)
()
# Data Cleaning Pipeline (R / tidyverse)
# Input: data/raw/raw_data.csv
# Output: data/clean/clean_data.rds
library(tidyverse)
library(janitor)
# --------------------------------------------------
# 1. Load and inspect
# --------------------------------------------------
df <- read_csv("data/raw/raw_data.csv")
glimpse(df)
summary(df)
colSums(is.na(df)) # missingness
# Check duplicates
cat("Duplicate rows:", sum(duplicated(df)), "\n")
df <- distinct(df)
# --------------------------------------------------
# 2. Standardize column names (snake_case)
# --------------------------------------------------
df <- clean_names(df) # janitor::clean_names
# --------------------------------------------------
# 3. Replace missing value codes
# --------------------------------------------------
MISSING_CODES
df df
mutateacrosswhere ifelse. MISSING_CODES .
winsorize x probs
qs quantilex probs na.rm
pminpmaxx qs qs
df df
mutateacrossincome wage winsorize
df df
mutate
log_income log1pincome
mi_income income
stopifnot dfid
duplicateddfid
dfincome na.rm
dir.create recursive showWarnings
saveRDSdf
catsprintf nrowdf ncoldf
Route empirical-research requests through the Auto-Empirical Research Skills catalog when this whole repository is installed as one skill in Codex, CodeBuddy, Claude Code, or another IDE. Use to choose and load the right vendored AERS skill for causal inference, econometrics, replication, data acquisition, manuscript writing, peer review and referee responses, citation checking, de-AIGC editing, or full empirical-paper workflows without reading the entire repository at once.
中英双语学术降 AIGC / bilingual academic de-AIGC skill. Removes AI-generated writing signatures from empirical papers in economics, management, and the social sciences — in both English and Chinese. Covers Turnitin AI, GPTZero, Originality.ai on the English side and 知网 AMLC, 万方, 维普 on the Chinese side. Uses a six-step loop (intake → audit → claim-evidence check → differentiated rewrite → five-dimension self-score → cold-reader recheck) with two pattern libraries (22 English + 17 Chinese patterns), section-by-section strategies for empirical papers, and hard protections that keep every number, coefficient, and citation intact.
Use when a research task needs reproducible Kaggle discovery, metadata inspection, bounded public-data downloads, competition or kernel discovery, model discovery, or an explicitly approved Kaggle write/delete operation through the official CLI.
基于 SOC 职业分类