cd /Users/jng2/Desktop capture log close set more off use househld, clear keep hhx tempfile households save `households', replace use familyxx, clear keep hhx fmx tempfile families save `families', replace use personsx, clear keep hhx fmx fpx region sex r_maritl fspous2 phstat notcov tempfile persons save `persons', replace use `households', clear merge 1:m hhx using `families' tab _merge keep if _merge==3 drop _merge merge 1:m hhx fmx using `persons' tab _merge keep if _merge==3 drop _merge keep if r_maritl==1 gen male=sex==1 *identify couples *first deal with the men preserve keep if male==1 rename fspous2 wifeid foreach v of varlist fpx region sex r_maritl phstat notcov male { rename `v' `v'_m } tempfile men save `men', replace restore *then deal with the women keep if male==0 gen wifeid=fpx foreach v of varlist fpx region sex r_maritl phstat notcov male { rename `v' `v'_f } *merge women to their husbands merge 1:1 hhx fmx wifeid using `men' tab _merge *bro if _merge!=3 keep if _merge==3 drop _merge su, sep(0) *sort obs. and reorder columns for better browsing sort hhx fmx order hhx* fmx* fpx* wifeid *identify and tag families with more than 1 couple duplicates tag hhx fmx, gen(multicoup) *bro if multicoup>0 *create unique ID for each couple egen coupleid = group(hhx fmx fpx_m fpx_f) order coupleid *reshape to long reshape long fpx region r_maritl phstat notcov male, i(coupleid) j(sex, string) *create dummy variables for phstat and notcov tab phstat, gen(dum_phstat) tab notcov, gen(dum_notcov) *print table of summ stats estpost su dum_* if male==0 eststo stats_f estpost su dum_* if male==1 eststo stats_m esttab stats_f stats_m, main(mean %6.2f) aux(sd) nostar /// mtitle("Women" "Men") /// title("Summary statistics of selected characteristics by sex") /// addn("Sample consists of matched husbands and wives from NHIS 2012.")