*! 1.1.0 14May98 (Jeroen Weesie/ICS) program define hhi version 5.0 * interface to hh package hh_is local hnr : char _dta[HH_nr] local sex : char _dta[HH_sex] * split in hhi-cmd and est-cmd parse "`*'", p(":") if "`1'" == ":" { local hhicmd mac shift 1 local estcmd "`*'" } else { if "`2'" != ":" { exit } local hhicmd "`1'" mac shift 2 local estcmd "`*'" } *di in gr "hhicmd: " in ye "`hhicmd'" *di in gr "estcmd: " in ye "`estcmd'" * drop HHI_VARS if "$HHI_VARS" != "" { parse "$HHI_VARS", p(" ") while "`1'" != "" { capture drop `1' mac shift } global HHI_VARS } * process hhi-cmd local if "opt" local in "opt" local options "ADd ANy ALl noKeep noLabel Preserv" parse "`hhicmd'" * message for inconsistency with STB documentation if "`keep'" ~= "" | "`label'" ~= "" { di in bl "Beware: defaults of keep/label in hhi differ from STB documentation" di in bl "Please consult the on-line help" } * sample selection tempvar touse hh_slct `if' `in', `any' `all' gen(`touse') * preserve data if "`preserv'" != "" { preserve } * sort into order HW HW HW HW ... sort `touse' `hnr' `sex' * substitute appropriate variables in est_cmd == ecmd vlist rest parse "`estcmd'", p(",[ ") local ecmd "`1'" mac shift while "`1'"!="" & "`1'"!="in" & "`1'"!="if" & "`1'"!="[" & "`1'"!="," { if substr("`1'",2,1) == "." { local c = upper(substr("`1'",1,1)) local v = substr("`1'",3,.) confirm exist `v' if "`add'" == "" { local v0 = substr("`v'",2,.) } else local v0 "`v'" if index("HWMDA","`c'") == 0 { di in re "unknown prefix function `c'" exit 198 } capture drop `c'`v0' if "`c'" == "H" { qui by `touse' `hnr': gen `c'`v0' = `v'[1] if _n==1 & `touse' } else if "`c'" == "W" { qui by `touse' `hnr': gen `c'`v0' = `v'[2] if _n==1 & `touse' } else if "`c'" == "M" { qui by `touse' `hnr': gen `c'`v0' = 0.5*(`v'[1]+`v'[2]) if _n==1 & `touse' } else if "`c'" == "D" { qui by `touse' `hnr': gen `c'`v0' = `v'[1]-`v'[2] if _n==1 & `touse' } else if "`c'" == "A" { qui by `touse' `hnr': gen `c'`v0' = abs(`v'[1]-`v'[2]) if _n==1 & `touse' } local vlist "`vlist' `c'`v0'" local vdrop "`vdrop' `c'`v0'" local vl : var label `v' label var `c'`v0' "`c' `vl'" if "`label'" == "" { if "`c'" == "H" { local lab "Husband" } if "`c'" == "W" { local lab "Wife" } if "`c'" == "M" { local lab "Mean(Husband,Wife)" } if "`c'" == "D" { local lab "Husband-Wife" } if "`c'" == "A" { local lab "Abs(Husband-Wife)" } di in gr "`c'`v0'" _col(10) "<- `lab'" _col(32) /* */ in gr "of `v'" _col(45) in wh "`vl'" } } else { capt by `touse' `hnr': assert `1'[1]==`1'[2] if `touse' if _rc { di in re "`1' is not constant within households" exit 198 } local vlist "`vlist' `1'" } mac shift } local rest "`*'" * substitute appropriate variables in est_cmd == ecmd vlist rest capt noi `ecmd' `vlist' `rest' if _rc { di in re "error in executing substituted command" di in re "`ecmd' `vlist' `rest'" exit 198 } * drop variables if "`preserv'" != "" { if "`keep'" == "" { restore, not global HHI_VARS "`vdrop'" } } else { if "`keep'" == "" { global HHI_VARS "`vdrop'" } else drop `vdrop' } end exit Table h.varname -> value of variable of husband w.varname -> value of variable of wife m.varname -> mean of values husband/wife d.varname -> value-of-husband - value-of-wife a.varname -> abs(value-of-husband - value-of-wife) varname -> should be constant within households 12345678 <- 111111111111111111111111111111 of 12345678 (label) Example hhi : est_cmd duration h.edu w.edu d.inc