Skip to content

Implement HFC checks 1,3-6 per DQAP coverage mapping - #2

Open
aleortiz-uchicago wants to merge 1 commit into
DevInnovationLab:mainfrom
aleortiz-uchicago:Alejandro/hfc_task
Open

Implement HFC checks 1,3-6 per DQAP coverage mapping#2
aleortiz-uchicago wants to merge 1 commit into
DevInnovationLab:mainfrom
aleortiz-uchicago:Alejandro/hfc_task

Conversation

@aleortiz-uchicago

Copy link
Copy Markdown

Implements the DQAP coverage mapping across the HFC pipeline.

  • 1-import: read raw .csv (was .dta); recode -888/-999 sentinels to missing, keep -666="Other" gate on hh_watersource/stored_container.
  • 3-missingness (data_02): consent + all always-asked fields + Section D conditional on stored_yn gate; share missing by enumerator.
  • 4-outliers (data_03): Tukey fences on resp_age, hh_size, hh_children, storage_time (excl. 99), treat_chlorine/boil, duration_min, child_age_*.
  • 5-constraints (data_04): fixed valid ranges + storage_time 0-72-or-99 + relational hh_children <= hh_size.
  • 6-surveylogic (data_05): consent/stored_yn/hh_children skip gates, Other-specify mismatches (C7->C8, D2->D3), diarrhea reverse skip, roster-count vs hh_children, head-under-18.

Full main.do runs clean in Stata 19 — no errors, all 8 sheets written.

- 1-import: read .csv (raw is CSV, not DTA); recode -888/-999 sentinels to
  missing (keep -666 = "Other" gate on hh_watersource/stored_container)
- 3-missingness: consent + all always-asked fields + Section D conditional
  on stored_yn gate, share missing by enumerator (data_02)
- 4-outliers: Tukey fences on resp_age, hh_size, hh_children, storage_time
  (excl. 99), treat_chlorine, treat_boil, duration_min, child_age_* (data_03)
- 5-constraints: fixed ranges + storage_time 0-72-or-99 + relational
  hh_children <= hh_size (data_04)
- 6-surveylogic: consent/stored_yn/hh_children skip gates, Other-specify
  mismatches, diarrhea reverse skip, roster count, head-under-18 (data_05)
Copilot AI review requested due to automatic review settings July 23, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements DQAP coverage mapping checks across the HFC Stata pipeline, producing standardized Excel outputs for missingness (by enumerator), outliers (Tukey fences), constraints (valid ranges + relational), and survey-logic/skip-pattern inconsistencies.

Changes:

  • Switched import to read raw .csv and recoded -888/-999 sentinel codes to Stata missing in 1-import.do.
  • Added automated outlier flagging via Tukey fences in 4-outliers.do and expanded constraint validation (including relational checks) in 5-constraints.do.
  • Implemented missingness reporting (conditional on gates) in 3-missingness.do and implemented multiple survey-logic/skip checks in 6-surveylogic.do with a unified “append then export once” pattern.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
code/1-import.do Imports CSV and standardizes sentinel missing codes for downstream checks.
code/3-missingness.do Computes per-enumerator missingness for always-asked and gated fields and exports to data_02.
code/4-outliers.do Flags outliers via Tukey fences for key numeric fields and exports to data_03.
code/5-constraints.do Flags fixed-range and relational constraint violations and exports to data_04.
code/6-surveylogic.do Flags skip-pattern and logic inconsistencies and exports to data_05.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread code/5-constraints.do
Comment on lines +41 to +46
use `base', clear
keep if !missing(`v') & (`v' < `lo' | `v' > `hi')
keep hh_id enumerator `v'
rename `v' value
gen variable = "`v'"
gen valid_range = "[`lo', `hi']"
Comment thread code/3-missingness.do
Comment on lines 48 to +52
gen byte _has_hhid = !missing(hh_id)
keep if consent == 1
collapse (count) n_surveys=_has_hhid (mean) pct_miss_consent=_miss_consent ///
/* (mean) pct_miss_storage=_miss_storage */ , by(enumerator)
* gsort -pct_miss_storage
format pct_miss_* %9.2f
collapse (count) n_surveys=_has_hhid (mean) _miss_*, by(enumerator)
rename _miss_* pct_miss_*
format pct_miss_* %9.3f
Comment thread code/6-surveylogic.do
Comment on lines +75 to +76
gen byte _bad = hh_children == 0 & ///
(!missing(child_name_1) & child_name_1 != "" | !missing(child_age_1))
Comment thread code/6-surveylogic.do
Comment on lines +154 to +156
egen _nchild = rownonmiss(child_age_1 child_age_2 child_age_3)
gen byte _bad = consent == 1 & !missing(hh_children) & hh_children <= 3 & _nchild != hh_children
keep if _bad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants