quietly: /// infile ptid mridate age male race weight height packyrs yrsquit alcoh physact /// chf chd stroke diabetes genhlth ldl alb crt plt sbp aai fev dsst atrophy /// whgrd numinf volinf obstime death /// using http://www.emersonstatistics.com/datasets/mri.txt g deadin5 = 0 replace deadin5 = 1 if obstime <= 5 * 365.25 ttest ldl, by(deadin5) // Model A regress ldl deadin5 // Model B g alivefor5 = 1 - deadin5 regress ldl alivefor5 ttest ldl, by(deadin5) unequal regress ldl deadin5, robust list male age if ldl==. twoway (scatter ldl age if male==1, jitter(2) col(blue)) /// (lowess ldl age if male==1, col(blue)) /// (scatter ldl age if male==0, jitter(1) col(pink) msymb(D)) /// (lowess ldl age if male==0, col(pink)) /// (lowess ldl age, col(black) xtitle("Age (years)") /// ytitle("LDL (mg/dL)") t1("Serum LDL by Age and Sex")), /// legend(label(5 "Both sexes (lowess)") label(1 "Males") /// label(2 "Males (lowess)") label(3 "Females") label(4 "Females (lowess)")) recode age 65/70=1 71/75=2 76/80=3 81/85=4 86/max=5, gen(ageCTG) bysort male: tabstat ldl, stat(n mean sd min q max) col(stat) by(ageCTG) tabstat ldl, stat(n mean sd min q max) col(stat) by(ageCTG) regress ldl age, robust regress ldl age pwcorr ldl age, sig