*! 1.0.1 15Apr97 (Jeroen Weesie/ICS) STB-43 dm58 program define hhcorr 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 local varlist "opt ex" local if "opt" local in "opt" local options "ANy ALl Label" parse "`*'" tempvar touse wife * deal with the household selection (-if- and -in-) hh_slct `if' `in' , `any' `all' gen(`touse') * header for table di if "`label'" != "" { di in gr " Husband-Wife" di in gr "Variable | #-of-HH Correlation Label" di in gr "---------+" _dup(55) "-" } else { di in gr " Husband-Wife ------ Husband ----- ------- Wife -------" di in gr "Variable | #-of-HH Correlation Mean Std.Dev Mean Std.Dev " di in gr "---------+" _dup(68) "-" } * data should be sorted: HW HW HW ..., sorted on -touse-, then women excluded sort `touse' `hnr' `sex' quietly replace `touse' = 0 if `sex'==2 * compute correlation over selected households parse "`varlist'", p(" ") while "`1'" != "" { * move the _wife score to husbands's record in variable t quietly gen `wife' = `1'[_n+1] if `touse' quietly corr `1' `wife' local obs = _result(1) local corr = _result(4) if "`label'" != "" { local vl : var label `1' #del ; di in gr "`1'" _col(10) "|" in ye _col(12) %6.0f `obs' _col(23) %7.4f `corr' in wh _col(35) "`vl'" ; #del cr } else { quietly summ `1' if `touse' local hmn = _result(3) local hsd = sqrt(_result(4)) quietly summ `wife' if `touse' local wmn = _result(3) local wsd = sqrt(_result(4)) #del ; di in gr "`1'" _col(10) "|" in ye _col(12) %6.0f `obs' _col(24) %7.4f `corr' _col(35) %9.0g `hmn' _col(46) %9.0g `hsd' _col(58) %9.0g `wmn' _col(69) %9.0g `wsd' ; #del cr } drop `wife' mac shift } end exit Husband-Wife Variable | #-of-HH Correlation Label ---------+------------------------------------------------------- 12345678 | 123456 -0.7651 1234567890123456789012345678901 Husband-Wife ------ Husband ----- ------- Wife ------- Variable | #-of-HH Correlation Mean Std.Dev Mean Std.Dev ---------+------------------------------------------------------------------- 12345678 | 123456 1234567 123456789 123456789 123456789 123456789 In a future version, I could include single as well as married/cohabitating people. Homo/lesbian people have to be excluded. |-------- male --------| |------- female -------| obs mean stddev obs mean stddev corr ---------+------------------------------------------------------------------ 12345678 | M 123456 12345678 12345678 123456 12345678 12345678 -0.1234 | S 123456 12345678 12345678 123456 12345678 12345678