[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F1PT169J5H8V2X85KWSRWS":3,"skill-same:01M7F1PT169J5H8V2X85KWSRWS":87},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":31,"commitSha":32,"skillDirectory":33,"forksCount":14,"repositoryHtmlUrl":34,"repositoryHomepageUrl":34,"ownerHtmlUrl":35,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":36,"install":37,"resources":50},"01M7F1PT169J5H8V2X85KWSRWS","stata-data-cleaning",null,"> Generates rigorous, reproducible Stata data-cleaning workflows that follow World Bank DIME Analytics conventions (`iefieldkit`, `ietoolkit`, `iefolder` DataWork structure, `ieboilstart`, `iecodebook`, `ieduplicates`, `iecompdup`, extended missing values, master datasets, encryption for PII, dynami","Mr-Nobody-Anonymous\u002FAll-skills","Mr-Nobody-Anonymous","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F184253119?v=4","01M7AEXFJHKTYQW5R0ZCQQTWFV","anonymous","01M7C00M3GQR4QKP9GZA42GFAK",0,"MIT","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: stata-data-cleaning\ndescription: \"> Generates rigorous, reproducible Stata data-cleaning workflows that follow World Bank DIME Analytics conventions (`iefieldkit`, `ietoolkit`, `iefolder` DataWork structure, `ieboilstart`, `iecodebook`, `ieduplicates`, `iecompdup`, extended missing values, master datasets, encryption for PII, dynami\"\ncategory: economics\nversion: 1.0.0\ndisable-model-invocation: false\nrisk: low\nsource: \"https:\u002F\u002Fgithub.com\u002FJonasWeinert\u002FEconAgentSkills\"\nsource_repository: \"JonasWeinert\u002FEconAgentSkills\"\nsource_path: \"_skills\u002Fdata\u002Fstata-data-cleaning\u002FSKILL.md\"\nlicense: \"MIT\"\nimported_at: \"2026-09-20\"\n---\n# Stata Data Cleaning\n\nGenerate rigorous, reproducible Stata data-cleaning code that follows DIME Analytics impact-evaluation conventions. The default style is `iefolder` + `iecodebook` + `ieduplicates` + extended missing values + labeled categorical variables — never hand-rolled `clear all` + `cd`.\n\n## Operating Principles\n\n1. **Reproducibility first.** Every cleaning script starts with `ieboilstart`, declares dynamic absolute paths via globals, and runs end-to-end from a clean Stata session. Never `cd`. Never overwrite raw data. Never commit PII to a public repo.\n2. **Identify and document, then fix.** DIME's [Data Cleaning](https:\u002F\u002Fdimewiki.worldbank.org\u002FData_Cleaning) guidance is explicit: prioritize identifying and documenting irregularities (outliers, illogical values, typos, duplicates, missing-value codes) before correcting them. Many fixes depend on the analysis design that the PI controls.\n3. **Codebooks, not ad-hoc do-files.** Use `iecodebook template` and `iecodebook apply` for repetitive renames\u002Flabels\u002Frecodes. Codebooks are human-readable, machine-applicable, and easier to review than long do-file blocks.\n4. **Master dataset is the single source of truth.** Time-invariant identifying information, sampling, and treatment assignment live in one master dataset per unit of observation. All other datasets link to it.\n5. **Numeric, labeled, and asserted.** Categorical variables stored numerically with value labels; survey codes stored as extended missing values (`.a`, `.b`, ..., `.z`) with labels; every cleaned dataset has `isid` and `assert` checks.\n\n## Decision Policy\n\nThis skill follows the repo-wide [Agent Policy](..\u002F..\u002FAGENT_POLICY.md). For cross-cutting data discipline (unit of analysis, ID variables, merging, master dataset, PII), this skill defers to [`working-with-data`](..\u002Fworking-with-data\u002F).\n\n**ASK before proceeding** (blocking):\n\n1. Unit of observation and the unique identifier (single or composite).\n2. Whether the file contains PII; if yes, is encryption already configured.\n3. How to resolve duplicates that `ieduplicates` finds (correction, update, keep_one, drop).\n4. Sample restrictions to apply; each `iedropone` is logged but the choice is the user's.\n5. For multi-wave projects: harmonization strategy across rounds (variable name remapping in `iecodebook append`).\n\n**DEFAULT + flag** (use this default; tell the user how to override):\n\n- DataWork folder layout via `iefolder` (DIME default).\n- `iecodebook` Excel-driven cleaning over hand-written rename\u002Frecode\u002Flabel blocks.\n- Extended missing values `.a` \"Don't know\", `.b` \"Refuse\", `.c` \"Not applicable\", `.n` \"Skipped (logic)\" with a single harmonized label set.\n- `encode ..., label() noextend` for string categoricals (errors when an unexpected value appears).\n- `ieboilsave` before every save; `ieboilstart 17.0` at the top of every script.\n\n**DOCUMENT and proceed** (write into the decisions log + `documentation\u002Fcleaning_log.md`):\n\n- Inferred unit of observation if not stated, with the assertion that confirms it.\n- Each filter applied and the resulting N.\n- Each value recode and which raw codes mapped where.\n- Choice of which extended missing letter maps to which survey code.\n\n`PROCEED` items: never `cd`; always reference paths as globals; raw is immutable; encrypted folder gitignored; `ieboilsave` checks before saving.\n\n## Pre-flight Checklist\n\nBefore writing code, confirm with the user — and write the answers in the do-file header:\n\n- **Data source.** Primary survey (CAPI export?), administrative, secondary, or API?\n- **Unit of observation.** Household, individual, firm, plot, school, country-year?\n- **Unique identifier.** Single ID variable (e.g. `hhid`)? Composite key (e.g. `hhid year`)?\n- **Survey rounds.** Single cross-section, panel waves, or repeated cross-sections?\n- **Sensitive content.** Does the raw data contain PII (names, GPS, dates of birth, contact info, photos)?\n- **Cleaning goals.** Recoding, harmonization across waves, de-duplication, missing-value handling, derived variables, or all of the above?\n- **Output.** Analysis-ready `.dta`, public-release de-identified `.dta`, or both?\n\n## DIME DataWork Layout\n\nEvery cleaning script assumes a `DataWork\u002F` folder created by `iefolder` (see [DataWork Folder](https:\u002F\u002Fdimewiki.worldbank.org\u002FDataWork_Folder)):\n\n```\nProjectABC\u002F\n├── DataWork\u002F\n│   ├── MasterDoFile.do\n│   ├── MasterData\u002F                          # Time-invariant info, sampling, treatment\n│   │   ├── master_household.dta             # de-identified\n│   │   └── master_household_PII.dta         # encrypted-only\n│   ├── EncryptedData\u002F                       # Anything PII (encrypted with VeraCrypt)\n│   │   ├── Baseline\u002F\n│   │   └── Endline\u002F\n│   └── Baseline\u002F\n│       ├── DataSets\u002F\n│       │   ├── Raw\u002F                         # IMMUTABLE; never edit\n│       │   ├── Intermediate\u002F\n│       │   └── Final\u002F                       # analysis-ready, de-identified\n│       ├── Dofiles\u002F\n│       │   ├── Cleaning\u002F\n│       │   ├── Construction\u002F                # derived variables\n│       │   └── Analysis\u002F\n│       ├── Output\u002F\n│       ├── Documentation\u002F\n│       └── Questionnaire\u002F\n└── README.md\n```\n\nPII rules ([DIME PII page](https:\u002F\u002Fdimewiki.worldbank.org\u002FPersonally_Identifiable_Information_(PII))):\n\n- All PII lives in `EncryptedData\u002F`, encrypted with VeraCrypt or equivalent.\n- The working dataset in `Final\u002F` is de-identified.\n- Never commit `EncryptedData\u002F` to git (`.gitignore` it).\n\n## Cleaning Workflow\n\n```\n1. Import raw data (CAPI exporter or read_csv) into Raw\u002F  - IMMUTABLE\n2. Validate IDs with ieduplicates \u002F isid\n3. Harmonize variables across waves with iecodebook append\n4. Apply codebook (iecodebook apply): rename, label, recode, drop\n5. Convert survey codes to extended missing values (.a, .b, ...)\n6. Convert string categorical to numeric labeled (encode ..., label() noextend)\n7. Construct derived variables in a separate construction do-file\n8. Validate with assert + isid + duplicates report\n9. Save Intermediate -> save Final -> save de-identified version\n10. Export iecodebook to Documentation\u002F\n```\n\n## Estimator-Free Decision Tree\n\n### Duplicates\n\n```\nduplicates report id_var\n  └── if any:\n       ieduplicates id_var, ...                # creates an Excel report\n       iecompdup id_var, ...                   # compare and resolve\n       Document resolution in Documentation\u002Fduplicates_log.xlsx\n```\n\n### Missing Values\n\n```\nSurvey codes (-99, -88, -77, -98 etc.):\n  └── Replace with extended missing values:\n       label define mvlbl .a \"Don't know\" .b \"Refuse\" .c \"Not applicable\"\n       mvdecode varlist, mv(-99=.a \\ -88=.b \\ -77=.c)\n       label values varlist mvlbl\n\nTrue missingness from survey skip patterns:\n  └── Use a distinct extended missing value (e.g. .n \"Not asked due to skip\")\n       so it is distinguishable from \"Don't know\".\n\nAfter cleaning, the Final dataset should contain no plain \".\" values\nin cleaned variables — every missing value should explain itself.\n```\n\n### Categorical Variables\n\n```\nNumeric categorical:\n  label define edu_lbl 1 \"None\" 2 \"Primary\" 3 \"Secondary\" 4 \"Tertiary\"\n  label values education edu_lbl\n\nString categorical:\n  encode region_string, gen(region) label(region_lbl) noextend\n  \u002F\u002F noextend ERRORS if a new value appears that is not in the predefined label\n```\n\n### IDs\n\n```\nisid hhid                                      # cross-section\nisid hhid year                                 # panel\nduplicates report hhid year                    # any duplicates?\nassert !missing(hhid, year)                    # IDs must be non-missing\n```\n\n### Outliers and Illogical Values\n\n```\n1. IDENTIFY before fixing (DIME guidance):\n     summarize varlist, detail\n     graph box varlist\n     scatter varlist xvar\n2. Document each anomaly in Documentation\u002Fcleaning_log.md\n3. Discuss with PI which to flag vs cap vs drop\n4. Apply correction in code, never by hand\n5. Tag with a flag variable: gen flag_outlier_y = (y > p99 & !mi(y))\n```\n\n## Output Skeleton\n\n```stata\n*-------------------------------------------------------------*\n* Project   : ProjectABC\n* Purpose   : Clean baseline household survey\n* Author    : First Last\n* Created   : 2026-05-05\n* Inputs    : ${baseline_raw}\u002Fbaseline_hh.dta  (CAPI export, IMMUTABLE)\n* Outputs   : ${baseline_int}\u002Fbaseline_hh_clean.dta\n*             ${baseline_doc}\u002Fbaseline_hh_codebook.xlsx\n*             ${master_data}\u002Fmaster_household.dta\n* Estimand  : N\u002FA (cleaning, not estimation)\n* PII       : raw contains names, GPS — handled in EncryptedData\u002F\n*-------------------------------------------------------------*\n\n* 0. Settings\nieboilstart, version(17.0)\n`r(version)'\n\n* 1. Load raw (NEVER overwrite)\nuse \"${baseline_raw}\u002Fbaseline_hh.dta\", clear\n\n* 2. ID validation\nieduplicates hhid using \"${baseline_doc}\u002Fduplicates_baseline.xlsx\", \u002F\u002F\u002F\n    uniquevars(hhid) keepvars(enum_id submission_date) \u002F\u002F\u002F\n    folder(\"${baseline_doc}\") \u002F\u002F\u002F\n    listofdiffs(diff_log_baseline) replace\n\nisid hhid\n\n* 3. Apply codebook (rename, label, recode in one shot)\niecodebook apply using \"${baseline_doc}\u002Fbaseline_codebook.xlsx\", \u002F\u002F\u002F\n    missingvalues(.a \"Don't know\" .b \"Refuse\" .c \"Not applicable\")\n\n* 4. Survey codes to extended missing values\nmvdecode age income, mv(-99=.a \\ -88=.b \\ -77=.c)\nmvdecode age income, mv(-98=.n)             \u002F\u002F .n = \"skipped due to logic\"\n\n* 5. String to labeled numeric\nencode region, gen(region_id) label(region_lbl) noextend\n\n* 6. Validation\nassert age >= 0 & age \u003C= 120 if !missing(age)\nassert inlist(female, 0, 1)               if !missing(female)\nisid hhid\n\n* 7. Save (with checks)\nieboilsave, \u002F\u002F\u002F\n    idvars(hhid) \u002F\u002F\u002F\n    versionvar(version_var)             \u002F\u002F adds version comment\nsave \"${baseline_int}\u002Fbaseline_hh_clean.dta\", replace\n\n* 8. Export codebook for documentation\niecodebook export using \"${baseline_doc}\u002Fbaseline_hh_codebook.xlsx\", replace\n```\n\n## Common Pitfalls\n\n- Hardcoded paths and `cd` — break collaboration; use globals defined in `MasterDoFile.do`.\n- Editing raw data — `Raw\u002F` is immutable; create `Intermediate\u002F` outputs.\n- Plain `.` for everything missing — kills downstream interpretation; use extended missing values with labels.\n- `encode` without `label() noextend` — silently rebases codes when new values appear; always pre-define the label.\n- Dropping rows without `iedropone` — silent drops break replication; `iedropone` errors if the count is unexpected.\n- Committing `EncryptedData\u002F` or files containing names, GPS, contact info to git.\n- Long ad-hoc rename\u002Flabel\u002Frecode blocks — replace with `iecodebook apply` driven by an Excel codebook.\n- Saving over the master dataset from a cleaning script — master is updated through a controlled process.\n\n## Additional Resources\n\n- `reference.md` — extended code patterns, codebook recipes, harmonization, and master-dataset workflow.\n- `examples\u002F` — runnable do-files:\n  - `examples\u002Fmaster_cleaning.do` — entry point that routes to all cleaning steps\n  - `examples\u002Fclean_with_iecodebook.do` — codebook-driven cleaning\n  - `examples\u002Fduplicates_workflow.do` — `ieduplicates` + `iecompdup`\n  - `examples\u002Fmissing_values_extended.do` — extended missing values for survey codes\n  - `examples\u002Fharmonize_waves_iecodebook.do` — `iecodebook append` across rounds\n  - `examples\u002Fmaster_dataset.do` — building and updating a master dataset\n  - `examples\u002Fdeidentify_for_release.do` — strip PII for public release\n\n## Requirements\n\n- Stata >= 16.\n- DIME packages: `iefieldkit` (provides `iecodebook`, `ieduplicates`, `iecompdup`, `ietestform`), `ietoolkit` (provides `iefolder`, `ieboilstart`, `ieboilsave`, `iedropone`).\n- Optional helpers: `mdesc`, `unique`, `labutil`, `fre`, `winsor2`, `quantiles` (for cross-checks).\n\n```stata\nssc install iefieldkit, replace\nssc install ietoolkit,  replace\nssc install mdesc,      replace\nssc install unique,     replace\nssc install labutil,    replace\nssc install fre,        replace\nssc install winsor2,    replace\n```\n\n## References\n\n### DIME Conventions\n\n- DIME Analytics, [Data Cleaning](https:\u002F\u002Fdimewiki.worldbank.org\u002FData_Cleaning)\n- DIME Analytics, [DataWork Folder](https:\u002F\u002Fdimewiki.worldbank.org\u002FDataWork_Folder)\n- DIME Analytics, [Master Do-files](https:\u002F\u002Fdimewiki.worldbank.org\u002FMaster_Do-files)\n- DIME Analytics, [iecodebook](https:\u002F\u002Fdimewiki.worldbank.org\u002FIecodebook)\n- DIME Analytics, [ietoolkit](https:\u002F\u002Fdimewiki.worldbank.org\u002Fietoolkit)\n- DIME Analytics, [iefieldkit](https:\u002F\u002Fdimewiki.worldbank.org\u002FIefieldkit)\n- DIME Analytics, [Personally Identifiable Information (PII)](https:\u002F\u002Fdimewiki.worldbank.org\u002FPersonally_Identifiable_Information_(PII))\n- DIME Analytics, [ID Variable Properties](https:\u002F\u002Fdimewiki.worldbank.org\u002FID_Variable_Properties)\n- DIME Analytics, [Reproducible Research](https:\u002F\u002Fdimewiki.worldbank.org\u002FReproducible_Research)\n- *Development Research in Practice* (DIME Analytics handbook).\n\n### Style References\n\n- Gentzkow & Shapiro (2014). *Code and Data for the Social Sciences*.\n- IPA, *Reproducible Research: Best Practices for Data and Code Management*.\n","# Stata Data Cleaning\n\nGenerate rigorous, reproducible Stata data-cleaning code that follows DIME Analytics impact-evaluation conventions. The default style is `iefolder` + `iecodebook` + `ieduplicates` + extended missing values + labeled categorical variables — never hand-rolled `clear all` + `cd`.\n\n## Operating Principles\n\n1. **Reproducibility first.** Every cleaning script starts with `ieboilstart`, declares dynamic absolute paths via globals, and runs end-to-end from a clean Stata session. Never `cd`. Never overwrite raw data. Never commit PII to a public repo.\n2. **Identify and document, then fix.** DIME's [Data Cleaning](https:\u002F\u002Fdimewiki.worldbank.org\u002FData_Cleaning) guidance is explicit: prioritize identifying and documenting irregularities (outliers, illogical values, typos, duplicates, missing-value codes) before correcting them. Many fixes depend on the analysis design that the PI controls.\n3. **Codebooks, not ad-hoc do-files.** Use `iecodebook template` and `iecodebook apply` for repetitive renames\u002Flabels\u002Frecodes. Codebooks are human-readable, machine-applicable, and easier to review than long do-file blocks.\n4. **Master dataset is the single source of truth.** Time-invariant identifying information, sampling, and treatment assignment live in one master dataset per unit of observation. All other datasets link to it.\n5. **Numeric, labeled, and asserted.** Categorical variables stored numerically with value labels; survey codes stored as extended missing values (`.a`, `.b`, ..., `.z`) with labels; every cleaned dataset has `isid` and `assert` checks.\n\n## Decision Policy\n\nThis skill follows the repo-wide [Agent Policy](..\u002F..\u002FAGENT_POLICY.md). For cross-cutting data discipline (unit of analysis, ID variables, merging, master dataset, PII), this skill defers to [`working-with-data`](..\u002Fworking-with-data\u002F).\n\n**ASK before proceeding** (blocking):\n\n1. Unit of observation and the unique identifier (single or composite).\n2. Whether the file contains PII; if yes, is encryption already configured.\n3. How to resolve duplicates that `ieduplicates` finds (correction, update, keep_one, drop).\n4. Sample restrictions to apply; each `iedropone` is logged but the choice is the user's.\n5. For multi-wave projects: harmonization strategy across rounds (variable name remapping in `iecodebook append`).\n\n**DEFAULT + flag** (use this default; tell the user how to override):\n\n- DataWork folder layout via `iefolder` (DIME default).\n- `iecodebook` Excel-driven cleaning over hand-written rename\u002Frecode\u002Flabel blocks.\n- Extended missing values `.a` \"Don't know\", `.b` \"Refuse\", `.c` \"Not applicable\", `.n` \"Skipped (logic)\" with a single harmonized label set.\n- `encode ..., label() noextend` for string categoricals (errors when an unexpected value appears).\n- `ieboilsave` before every save; `ieboilstart 17.0` at the top of every script.\n\n**DOCUMENT and proceed** (write into the decisions log + `documentation\u002Fcleaning_log.md`):\n\n- Inferred unit of observation if not stated, with the assertion that confirms it.\n- Each filter applied and the resulting N.\n- Each value recode and which raw codes mapped where.\n- Choice of which extended missing letter maps to which survey code.\n\n`PROCEED` items: never `cd`; always reference paths as globals; raw is immutable; encrypted folder gitignored; `ieboilsave` checks before saving.\n\n## Pre-flight Checklist\n\nBefore writing code, confirm with the user — and write the answers in the do-file header:\n\n- **Data source.** Primary survey (CAPI export?), administrative, secondary, or API?\n- **Unit of observation.** Household, individual, firm, plot, school, country-year?\n- **Unique identifier.** Single ID variable (e.g. `hhid`)? Composite key (e.g. `hhid year`)?\n- **Survey rounds.** Single cross-section, panel waves, or repeated cross-sections?\n- **Sensitive content.** Does the raw data contain PII (names, GPS, dates of birth, contact info, photos)?\n- **Cleaning goals.** Recoding, harmonization across waves, de-duplication, missing-value handling, derived variables, or all of the above?\n- **Output.** Analysis-ready `.dta`, public-release de-identified `.dta`, or both?\n\n## DIME DataWork Layout\n\nEvery cleaning script assumes a `DataWork\u002F` folder created by `iefolder` (see [DataWork Folder](https:\u002F\u002Fdimewiki.worldbank.org\u002FDataWork_Folder)):\n\n```\nProjectABC\u002F\n├── DataWork\u002F\n│   ├── MasterDoFile.do\n│   ├── MasterData\u002F                          # Time-invariant info, sampling, treatment\n│   │   ├── master_household.dta             # de-identified\n│   │   └── master_household_PII.dta         # encrypted-only\n│   ├── EncryptedData\u002F                       # Anything PII (encrypted with VeraCrypt)\n│   │   ├── Baseline\u002F\n│   │   └── Endline\u002F\n│   └── Baseline\u002F\n│       ├── DataSets\u002F\n│       │   ├── Raw\u002F                         # IMMUTABLE; never edit\n│       │   ├── Intermediate\u002F\n│       │   └── Final\u002F                       # analysis-ready, de-identified\n│       ├── Dofiles\u002F\n│       │   ├── Cleaning\u002F\n│       │   ├── Construction\u002F                # derived variables\n│       │   └── Analysis\u002F\n│       ├── Output\u002F\n│       ├── Documentation\u002F\n│       └── Questionnaire\u002F\n└── README.md\n```\n\nPII rules ([DIME PII page](https:\u002F\u002Fdimewiki.worldbank.org\u002FPersonally_Identifiable_Information_(PII))):\n\n- All PII lives in `EncryptedData\u002F`, encrypted with VeraCrypt or equivalent.\n- The working dataset in `Final\u002F` is de-identified.\n- Never commit `EncryptedData\u002F` to git (`.gitignore` it).\n\n## Cleaning Workflow\n\n```\n1. Import raw data (CAPI exporter or read_csv) into Raw\u002F  - IMMUTABLE\n2. Validate IDs with ieduplicates \u002F isid\n3. Harmonize variables across waves with iecodebook append\n4. Apply codebook (iecodebook apply): rename, label, recode, drop\n5. Convert survey codes to extended missing values (.a, .b, ...)\n6. Convert string categorical to numeric labeled (encode ..., label() noextend)\n7. Construct derived variables in a separate construction do-file\n8. Validate with assert + isid + duplicates report\n9. Save Intermediate -> save Final -> save de-identified version\n10. Export iecodebook to Documentation\u002F\n```\n\n## Estimator-Free Decision Tree\n\n### Duplicates\n\n```\nduplicates report id_var\n  └── if any:\n       ieduplicates id_var, ...                # creates an Excel report\n       iecompdup id_var, ...                   # compare and resolve\n       Document resolution in Documentation\u002Fduplicates_log.xlsx\n```\n\n### Missing Values\n\n```\nSurvey codes (-99, -88, -77, -98 etc.):\n  └── Replace with extended missing values:\n       label define mvlbl .a \"Don't know\" .b \"Refuse\" .c \"Not applicable\"\n       mvdecode varlist, mv(-99=.a \\ -88=.b \\ -77=.c)\n       label values varlist mvlbl\n\nTrue missingness from survey skip patterns:\n  └── Use a distinct extended missing value (e.g. .n \"Not asked due to skip\")\n       so it is distinguishable from \"Don't know\".\n\nAfter cleaning, the Final dataset should contain no plain \".\" values\nin cleaned variables — every missing value should explain itself.\n```\n\n### Categorical Variables\n\n```\nNumeric categorical:\n  label define edu_lbl 1 \"None\" 2 \"Primary\" 3 \"Secondary\" 4 \"Tertiary\"\n  label values education edu_lbl\n\nString categorical:\n  encode region_string, gen(region) label(region_lbl) noextend\n  \u002F\u002F noextend ERRORS if a new value appears that is not in the predefined label\n```\n\n### IDs\n\n```\nisid hhid                                      # cross-section\nisid hhid year                                 # panel\nduplicates report hhid year                    # any duplicates?\nassert !missing(hhid, year)                    # IDs must be non-missing\n```\n\n### Outliers and Illogical Values\n\n```\n1. IDENTIFY before fixing (DIME guidance):\n     summarize varlist, detail\n     graph box varlist\n     scatter varlist xvar\n2. Document each anomaly in Documentation\u002Fcleaning_log.md\n3. Discuss with PI which to flag vs cap vs drop\n4. Apply correction in code, never by hand\n5. Tag with a flag variable: gen flag_outlier_y = (y > p99 & !mi(y))\n```\n\n## Output Skeleton\n\n```stata\n*-------------------------------------------------------------*\n* Project   : ProjectABC\n* Purpose   : Clean baseline household survey\n* Author    : First Last\n* Created   : 2026-05-05\n* Inputs    : ${baseline_raw}\u002Fbaseline_hh.dta  (CAPI export, IMMUTABLE)\n* Outputs   : ${baseline_int}\u002Fbaseline_hh_clean.dta\n*             ${baseline_doc}\u002Fbaseline_hh_codebook.xlsx\n*             ${master_data}\u002Fmaster_household.dta\n* Estimand  : N\u002FA (cleaning, not estimation)\n* PII       : raw contains names, GPS — handled in EncryptedData\u002F\n*-------------------------------------------------------------*\n\n* 0. Settings\nieboilstart, version(17.0)\n`r(version)'\n\n* 1. Load raw (NEVER overwrite)\nuse \"${baseline_raw}\u002Fbaseline_hh.dta\", clear\n\n* 2. ID validation\nieduplicates hhid using \"${baseline_doc}\u002Fduplicates_baseline.xlsx\", \u002F\u002F\u002F\n    uniquevars(hhid) keepvars(enum_id submission_date) \u002F\u002F\u002F\n    folder(\"${baseline_doc}\") \u002F\u002F\u002F\n    listofdiffs(diff_log_baseline) replace\n\nisid hhid\n\n* 3. Apply codebook (rename, label, recode in one shot)\niecodebook apply using \"${baseline_doc}\u002Fbaseline_codebook.xlsx\", \u002F\u002F\u002F\n    missingvalues(.a \"Don't know\" .b \"Refuse\" .c \"Not applicable\")\n\n* 4. Survey codes to extended missing values\nmvdecode age income, mv(-99=.a \\ -88=.b \\ -77=.c)\nmvdecode age income, mv(-98=.n)             \u002F\u002F .n = \"skipped due to logic\"\n\n* 5. String to labeled numeric\nencode region, gen(region_id) label(region_lbl) noextend\n\n* 6. Validation\nassert age >= 0 & age \u003C= 120 if !missing(age)\nassert inlist(female, 0, 1)               if !missing(female)\nisid hhid\n\n* 7. Save (with checks)\nieboilsave, \u002F\u002F\u002F\n    idvars(hhid) \u002F\u002F\u002F\n    versionvar(version_var)             \u002F\u002F adds version comment\nsave \"${baseline_int}\u002Fbaseline_hh_clean.dta\", replace\n\n* 8. Export codebook for documentation\niecodebook export using \"${baseline_doc}\u002Fbaseline_hh_codebook.xlsx\", replace\n```\n\n## Common Pitfalls\n\n- Hardcoded paths and `cd` — break collaboration; use globals defined in `MasterDoFile.do`.\n- Editing raw data — `Raw\u002F` is immutable; create `Intermediate\u002F` outputs.\n- Plain `.` for everything missing — kills downstream interpretation; use extended missing values with labels.\n- `encode` without `label() noextend` — silently rebases codes when new values appear; always pre-define the label.\n- Dropping rows without `iedropone` — silent drops break replication; `iedropone` errors if the count is unexpected.\n- Committing `EncryptedData\u002F` or files containing names, GPS, contact info to git.\n- Long ad-hoc rename\u002Flabel\u002Frecode blocks — replace with `iecodebook apply` driven by an Excel codebook.\n- Saving over the master dataset from a cleaning script — master is updated through a controlled process.\n\n## Additional Resources\n\n- `reference.md` — extended code patterns, codebook recipes, harmonization, and master-dataset workflow.\n- `examples\u002F` — runnable do-files:\n  - `examples\u002Fmaster_cleaning.do` — entry point that routes to all cleaning steps\n  - `examples\u002Fclean_with_iecodebook.do` — codebook-driven cleaning\n  - `examples\u002Fduplicates_workflow.do` — `ieduplicates` + `iecompdup`\n  - `examples\u002Fmissing_values_extended.do` — extended missing values for survey codes\n  - `examples\u002Fharmonize_waves_iecodebook.do` — `iecodebook append` across rounds\n  - `examples\u002Fmaster_dataset.do` — building and updating a master dataset\n  - `examples\u002Fdeidentify_for_release.do` — strip PII for public release\n\n## Requirements\n\n- Stata >= 16.\n- DIME packages: `iefieldkit` (provides `iecodebook`, `ieduplicates`, `iecompdup`, `ietestform`), `ietoolkit` (provides `iefolder`, `ieboilstart`, `ieboilsave`, `iedropone`).\n- Optional helpers: `mdesc`, `unique`, `labutil`, `fre`, `winsor2`, `quantiles` (for cross-checks).\n\n```stata\nssc install iefieldkit, replace\nssc install ietoolkit,  replace\nssc install mdesc,      replace\nssc install unique,     replace\nssc install labutil,    replace\nssc install fre,        replace\nssc install winsor2,    replace\n```\n\n## References\n\n### DIME Conventions\n\n- DIME Analytics, [Data Cleaning](https:\u002F\u002Fdimewiki.worldbank.org\u002FData_Cleaning)\n- DIME Analytics, [DataWork Folder](https:\u002F\u002Fdimewiki.worldbank.org\u002FDataWork_Folder)\n- DIME Analytics, [Master Do-files](https:\u002F\u002Fdimewiki.worldbank.org\u002FMaster_Do-files)\n- DIME Analytics, [iecodebook](https:\u002F\u002Fdimewiki.worldbank.org\u002FIecodebook)\n- DIME Analytics, [ietoolkit](https:\u002F\u002Fdimewiki.worldbank.org\u002Fietoolkit)\n- DIME Analytics, [iefieldkit](https:\u002F\u002Fdimewiki.worldbank.org\u002FIefieldkit)\n- DIME Analytics, [Personally Identifiable Information (PII)](https:\u002F\u002Fdimewiki.worldbank.org\u002FPersonally_Identifiable_Information_(PII))\n- DIME Analytics, [ID Variable Properties](https:\u002F\u002Fdimewiki.worldbank.org\u002FID_Variable_Properties)\n- DIME Analytics, [Reproducible Research](https:\u002F\u002Fdimewiki.worldbank.org\u002FReproducible_Research)\n- *Development Research in Practice* (DIME Analytics handbook).\n\n### Style References\n\n- Gentzkow & Shapiro (2014). *Code and Data for the Social Sciences*.\n- IPA, *Reproducible Research: Best Practices for Data and Code Management*.\n",{"name":5,"risk":24,"source":25,"license":15,"version":26,"category":27,"description":7,"imported_at":28,"source_path":29,"source_repository":30,"disable-model-invocation":20},"low","https:\u002F\u002Fgithub.com\u002FJonasWeinert\u002FEconAgentSkills","1.0.0","economics","2026-09-20","_skills\u002Fdata\u002Fstata-data-cleaning\u002FSKILL.md","JonasWeinert\u002FEconAgentSkills","main","2d1750717747097b602acf30bd09a7cbd4b4c6ea","awesome_skills\u002Feconomics\u002Fstata-data-cleaning","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous","2026-11-09 11:45:36",{"source":8,"skillName":5,"commands":38,"prompt":48,"zipAvailable":49},[39,42,45],{"tool":40,"command":41},"npx","npx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill stata-data-cleaning",{"tool":43,"command":44},"bunx","bunx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill stata-data-cleaning",{"tool":46,"command":47},"pnpm","pnpm dlx skills add Mr-Nobody-Anonymous\u002FAll-skills --skill stata-data-cleaning","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002FSKILL.md",true,[51,57,61,65,69,73,77,81],{"path":52,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":55,"sourceHtmlUrl":56},"examples\u002Fclean_with_iecodebook.do","OTHER","其他",1838,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fclean_with_iecodebook.do",{"path":58,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":59,"sourceHtmlUrl":60},"examples\u002Fdeidentify_for_release.do",2390,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fdeidentify_for_release.do",{"path":62,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":63,"sourceHtmlUrl":64},"examples\u002Fduplicates_workflow.do",1456,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fduplicates_workflow.do",{"path":66,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":67,"sourceHtmlUrl":68},"examples\u002Fharmonize_waves_iecodebook.do",1785,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fharmonize_waves_iecodebook.do",{"path":70,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":71,"sourceHtmlUrl":72},"examples\u002Fmaster_cleaning.do",915,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fmaster_cleaning.do",{"path":74,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":75,"sourceHtmlUrl":76},"examples\u002Fmaster_dataset.do",1883,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fmaster_dataset.do",{"path":78,"resourceType":53,"resourceTypeDesc":54,"sizeBytes":79,"sourceHtmlUrl":80},"examples\u002Fmissing_values_extended.do",1847,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Fexamples\u002Fmissing_values_extended.do",{"path":82,"resourceType":83,"resourceTypeDesc":84,"sizeBytes":85,"sourceHtmlUrl":86},"reference.md","REFERENCE","参考文档",7261,"https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Feconomics\u002Fstata-data-cleaning\u002Freference.md",[88,95,102,109,116,123],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7FFFZPC2025JQQHPHDX154J","dei-assessment","Assess diversity, equity, and inclusion with metrics. TRIGGERS - Use when user needs help with dei-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-assessment\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":19},"01M7FFFWN8H4WA7A6Y398QKB6J","dei-action-plan","Create DEI action plans with goals and initiatives. TRIGGERS - Use when user needs help with dei-action-plan related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fdei-action-plan\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":19},"01M7FFFSHTM0QZRVZ2NRJTJ0PY","culture-fit-assessment","Design culture add assessment processes. TRIGGERS - Use when user needs help with culture-fit-assessment related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fculture-fit-assessment\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":19},"01M7FFFMA12RKEQA38KHJSXXPS","cowork-to-code-bridge","Use an already-installed, independently verified cowork-to-code bridge to run narrowly approved actions on the user's own macOS, Linux, or WSL2 machine through a local file queue.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcowork-to-code-bridge\u002FSKILL.md",[],[],{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":19},"01M7FFFH1F6M8YRGW5V487GH1K","counter-offer-response","Draft counter-offer responses for retention. TRIGGERS - Use when user needs help with counter-offer-response related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcounter-offer-response\u002FSKILL.md",[],[],{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":19},"01M7FFFDGEHV8Y7J9N40HZXW52","continuous-feedback-system","Design continuous feedback systems. TRIGGERS - Use when user needs help with continuous-feedback-system related tasks.","https:\u002F\u002Fgithub.com\u002FMr-Nobody-Anonymous\u002FAll-skills\u002Fblob\u002Fmain\u002Fawesome_skills\u002Fhr-people\u002Fcontinuous-feedback-system\u002FSKILL.md",[],[]]