*! 1.0.1 15Apr97 (Jeroen Weesie/ICS) STB-43 dm58 program define hhset version 5.0 * echo description if "`*'" == "" { st_is hhreport exit } local varlist "min(2) max(2)" local options "Partner(str) Verify" parse "`*'" * use meanful macro names (hnr, sex) for household identification and sex parse "`varlist'", p(" ") local hnr "`1'" local sex "`2'" capt drop HH_idrop * hnr should never be missing nomiss `hnr' * is -sex- well-defined nomiss `sex' capt assert `sex'==1 | `sex'==2 if _rc { di in re "the variable -sex- should be coded 1=Male 2=Female" exit 198 } if "`verify'" != "" { local vall : value label `sex' if "`vall'" != "" { di _n in gr "Verify the meaning of the value labels: " /* */ "1 = Husband, 2 = Wife" label list `vall' di } } * via the -partner- variable, children etc can be excluded if "`partner'" != "" { confirm exist `partner' nomiss `partner' capt assert `partner'==0 | `partner'==1 if _rc { di in re "the variable `partner' should be 0-1 coded" exit 198 } tempvar npart quiet egen `npart' = sum(`partner'), by(`hnr') quiet count if (`npart'!=0) & (`npart'!=2) if _result(1) > 0 { di in re "Households should contain 0 or 2 partners." exit 198 } } else { * verify that each household consists of at most 2 individuals sort `hnr' capt quiet by `hnr': assert _N<=2 if _rc { di in re "A household should contain at most 2 persons (records)" di in re "Specify the -partner- option to identify husband & wife" exit 198 } } * HH_idrop specifies the individuals not in a heterosexual couple confirm new var HH_idrop if "`partner'" != "" { quiet gen byte HH_idrop = !`partner' } else { sort `hnr' quiet by `hnr': gen byte HH_idrop = (_N==1) } quiet count if HH_idrop if _result(1) > 0 { di in ye _result(1) in gr " individuals are partner-less" } tempvar homo sort HH_idrop `hnr' `sex' quiet by HH_idrop `hnr' : /* */ gen byte `homo' = (`sex'[1]==`sex'[2]) if !HH_idrop quiet count if `homo'==1 if _result(1) > 0 { di in ye _result(1) in gr " individuals in " in ye _result(1)/2 /* */ in gr " homosexual couples" } quiet replace HH_idrop = 1 if `homo' quiet count if HH_idrop==0 if _result(1) > 0 { di in ye _result(1) in gr " individuals in " in ye _result(1)/2 /* */ in gr " heterosexual couples" } * store information in characteristics label var HH_idrop "HH: marks obs not in H-W-couple" char _dta[HH_nr] "`hnr'" /* household number */ char _dta[HH_sex] "`sex'" /* sex of partner, 1=Male 2=Female */ char _dta[HH_idrop] "HH_idrop" /* !0 if not part of MF-couple */ * report key variables hhreport end * syntax: nomiss * purpose: asserts that a variable contains no missing values program define nomiss capt assert `1' != . if _rc { di in re "variable `1' should be non-missing" exit 198 } end * report key variables program define hhreport local hnr : char _dta[HH_nr] local sex : char _dta[HH_sex] local idrop : char _dta[HH_idrop] di di in gr "household identification: " in ye "`hnr'" di in gr "sex identification: " in ye "`sex'" di in gr "selected case identifier " in ye "`idrop'" end