*! 1.0.1 15Apr97 (Jeroen Weesie/ICS) STB-43 dm58 program define hhcount version 5.0 * interface with hh hh_is local hnr : char _dta[HH_nr] local sex : char _dta[HH_sex] local idrop : char _dta[HH_idrop] * parse command line * prepend = if necessary local cmd "`*'" if substr("`cmd'",1,1) != "=" { local cmd "=`cmd'" } local exp "req nopref" local if "opt" local in "opt" local options "ANy ALl *" parse "`cmd'" * deal with the household selection (-if- and -in-) tempvar touse hh_slct `if' `in' , `any' `all' gen(`touse') * the cases should be sorted on household-number and sex sort `touse' `hnr' `sex' * generate _Hisband & _Wife capt drop _Husband capt drop _Wife quiet gen _Husband = `exp' if `touse' quiet gen _Wife = _Husband[_n+1] if `touse' & `sex'==1 capt label drop __NoYes label def __NoYes 0 "no" 1 "yes" label value _Husband __NoYes label value _Wife __NoYes * display table capt assert (_Husband==_Wife) if `touse' & `sex'==1 if _rc { di _n in gr "Husband x Wife tabulation of " in ye "`exp'" tab _Husband _Wife if `touse', `options' } else { di in gr "Expression " in ye "`exp'" in gr " does not vary within households" tab _Wife if `touse' & _Wife != . } * remove the scratch variables capt label drop __NoYes capt drop _Husband capt drop _Wife end