************************OBESITY PARADOX*********************************** * Code for "Obesity Paradox: Conditioning on Disease Enhances Biases" * Last updated on October 19, 2013 * Establish directories global raw "C:\Users\astokes\Desktop\Data\NHANES" global out "C:\Users\astokes\Desktop\Projects\Obesity Paradox\stata output" global log "C:\Users\astokes\Desktop\Projects\Obesity Paradox\Log Files" global tables "C:\Users\astokes\Desktop\Projects\Obesity Paradox\results\tables" * Set-up capture log close set more off * Input/combine cleaned NHANES 3 and continuous data sets use "$out\masterNH3.dta", replace append using "$out\masterNH4.dta" * Declare features of survey design svyset psu [pweight=sweight], strata(strata) * Ages keep if age_exam >=35 & age_exam < 75 * Eliminate missing and outlier cases on key variables drop if bmi_m == . drop if bmi_m < 18.5 drop if diab_m == . drop if smoke == . * Construct indicators for body mass index gen bmicat = . gen normal = bmi_m >=18.5 & bmi_m < 25 gen over = bmi_m >=25 & bmi_m < 30 gen obese1 = bmi_m >=30 & bmi_m < 35 gen obese2 = bmi_m >=35 gen obese = bmi_m >=30 * Ever-Smoking gen smoke_ever = . replace smoke_ever = 0 if smoke == 0 replace smoke_ever = 1 if inlist(smoke,1,2) * Prepare for age-standardization gen agecat = . replace agecat = 1 if age_exam >= 35 & age_exam < 40 & male == 0 replace agecat = 2 if age_exam >= 40 & age_exam < 45 & male == 0 replace agecat = 3 if age_exam >= 45 & age_exam < 50 & male == 0 replace agecat = 4 if age_exam >= 50 & age_exam < 55 & male == 0 replace agecat = 5 if age_exam >= 55 & age_exam < 60 & male == 0 replace agecat = 6 if age_exam >= 60 & age_exam < 65 & male == 0 replace agecat = 7 if age_exam >= 65 & age_exam < 70 & male == 0 replace agecat = 8 if age_exam >= 70 & age_exam < 75 & male == 0 replace agecat = 9 if age_exam >= 35 & age_exam < 40 & male == 1 replace agecat = 10 if age_exam >= 40 & age_exam < 45 & male == 1 replace agecat = 11 if age_exam >= 45 & age_exam < 50 & male == 1 replace agecat = 12 if age_exam >= 50 & age_exam < 55 & male == 1 replace agecat = 13 if age_exam >= 55 & age_exam < 60 & male == 1 replace agecat = 14 if age_exam >= 60 & age_exam < 65 & male == 1 replace agecat = 15 if age_exam >= 65 & age_exam < 70 & male == 1 replace agecat = 16 if age_exam >= 70 & age_exam < 75 & male == 1 g stdist=. replace stdist=0.090746458 if agecat==1 replace stdist=0.090147161 if agecat==2 replace stdist=0.081303078 if agecat==3 replace stdist=0.071540922 if agecat==4 replace stdist=0.055465685 if agecat==5 replace stdist=0.045172706 if agecat==6 replace stdist=0.040904415 if agecat==7 replace stdist=0.039480789 if agecat==8 replace stdist=0.090194455 if agecat==9 replace stdist=0.088683651 if agecat==10 replace stdist=0.078805775 if agecat==11 replace stdist=0.068591733 if agecat==12 replace stdist=0.051865627 if agecat==13 replace stdist=0.040931859 if agecat==14 replace stdist=0.035064839 if agecat==15 replace stdist=0.031100846 if agecat==16 *drop if bmi_m >=25 & bmi_m < 30 /* Sensitivity Analysis */ tempfile temp save `temp', replace * TABLE 1 (Smoking Distribution in Source and Dysglycemic Population) use `temp', clear * SMOKING * total population svy : proportion smoke, stdize(agecat) stdweight(stdist) matrix temp1 = e(b)' svy, subpop(if normal==0): proportion smoke, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') svy, subpop(if normal==1): proportion smoke, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') * dysglycemia svy, subpop(if diab_m==1) : proportion smoke, stdize(agecat) stdweight(stdist) matrix temp2 = e(b)' svy, subpop(if diab_m==1 & normal==0): proportion smoke, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') svy, subpop(if diab_m==1 & normal==1): proportion smoke, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') matrix tempsmoke = (temp1\temp2) matlist tempsmoke * HEAVY SMOKING gen smoke_heavy = . replace smoke_heavy = 1 if inlist(smoke2, 3,4) replace smoke_heavy = 0 if inlist(smoke2, 0,1,2) * total population svy : proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp1 = e(b)' svy, subpop(if normal==0): proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') svy, subpop(if normal==1): proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') * dysglycemia svy, subpop(if diab_m==1) : proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp2 = e(b)' svy, subpop(if diab_m==1 & normal==0): proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') svy, subpop(if diab_m==1 & normal==1): proportion smoke_heavy, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') matrix tempheavysmoke = (temp1\temp2) matlist tempheavysmoke * LONG-DURATION SMOKING gen smoke_longdur = . replace smoke_longdur = 1 if smoking_duration_c >=20 replace smoke_longdur = 0 if smoking_duration_c < 20 replace smoke_longdur = . if smoking_duration_c == . * total population svy : proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp1 = e(b)' svy, subpop(if normal==0): proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') svy, subpop(if normal==1): proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') * dysglycemia svy, subpop(if diab_m==1) : proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp2 = e(b)' svy, subpop(if diab_m==1 & normal==0): proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') svy, subpop(if diab_m==1 & normal==1): proportion smoke_longdur, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') matrix templongsmoke = (temp1\temp2) matlist templongsmoke * EDUCATION (This is a check only; these results are not used) * total population svy : proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp1 = e(b)' svy, subpop(if normal==0): proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') svy, subpop(if normal==1): proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp1 = (temp1, e(b)') * dysglycemia svy, subpop(if diab_m==1) : proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp2 = e(b)' svy, subpop(if diab_m==1 & normal==0): proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') svy, subpop(if diab_m==1 & normal==1): proportion edu_recode, stdize(agecat) stdweight(stdist) matrix temp2 = (temp2, e(b)') matrix tempedu = (temp1\temp2) * COMBINE ALL THE MATRICES TOGETHER matrix temp = (tempsmoke\tempheavysmoke\templongsmoke\tempedu) mat colnames temp = all overob normal matlist temp drop _all svmat temp,names(col) export excel using "$tables\tablesraw.xlsx", sheet("raw t1") sheetreplace * TABLE 2 (Frequency of illness, poor health and weight loss) * dysglycemia (missing=0) * emphysema (missing=12) * smoking-related cancer (missing=10) * other cancer (missing=10) * stroke (missing=12) * heart attack (missing=127) * Congestive heart failure (missing=9048; completely missing in NH3; 31 missing in NH CTS) * Coronary heart disease (missing=9052; completely missing in NH3; 35 missing in NH CTS) * Angina (missing=9056; completely missing in NH3; 39 missing in NH CTS) * poor self-rated health (3 missing in NH 3; completely missing in NH CTS 1999-2000; 271 missing in NH CTS 2001-2004) * weight loss (missing: 1313; 1001 missing in NH 3; 312 missing in NH CTS) use `temp', clear * Weight loss gen wc = bmi_m - bmi10 gen weight_loss = wc < -2.2 replace weight_loss = . if wc==. * SOURCE POPULATION local varname "diab_m c_emphysema c_cancer_smoking c_cancer_other c_heartat c_chd c_angina c_congestive c_stroke health weight_loss" foreach v of local varname { if "`v'" == "diab_m"{ svy: mean `v', stdize(agecat) stdweight(stdist) matrix M = e(b)' } else{ svy: mean `v', stdize(agecat) stdweight(stdist) matrix M=(M,e(b)') } } mat colnames M = `varname' matlist M * DYSGLYCEMIC POPULATION local varname "diab_m c_emphysema c_cancer_smoking c_cancer_other c_heartat c_chd c_angina c_congestive c_stroke health weight_loss" foreach v of local varname { if "`v'" == "diab_m"{ svy, subpop(if diab_m==1): mean `v', stdize(agecat) stdweight(stdist) matrix D = e(b)' } else{ svy, subpop(if diab_m==1): mean `v', stdize(agecat) stdweight(stdist) matrix D=(D,e(b)') } } mat colnames D = `varname' matlist D matrix M=(M\D) matlist M drop _all svmat M,names(col) local percents "diab_m c_emphysema c_cancer_smoking c_cancer_other c_heartat c_chd c_angina c_congestive c_stroke health weight_loss" foreach p of local percents{ replace `p' = `p' * 100 } xpose, clear varname rename v1 source rename v2 dysglycemic order _varname source dysglycemic export excel using "$tables\tablesraw.xlsx", sheet("raw t2") sheetreplace firstrow(varlabels) * TABLE 3 (Mortality Rates by Weight Status and Ever Smoking) clear use `temp', clear gen subpop_d = diab_m == 1 stset censorage, id(seqn) failure(failure==1) enter(time startage) scale(12) if(subpop_d) gen fup = _t - _t0 drop agecat stdist stsplit agecat, at(35 60) // age-standardization using five-year age gen agecat1 = . replace agecat1 = 1 if agecat == 35 replace agecat1 = 2 if agecat == 60 g stdist=. replace stdist= 0.616394692 if agecat1==1 replace stdist= 0.383605308 if agecat1==2 gen py = _t-_t0 // person-years drop if py == . * compile table 2 * x = survey index forvalues x = 0(1)2{ matrix M = (99 \ 99 \ 99) matrix M = (M, (`x' \ `x' \ `x')) matrix M = (M,(1\2\3)) if `x' == 0 | `x' == 1{ svy, subpop(if diab_m==1 & smoke_ever==`x'): ratio _d/py, over(normal) stdize(agecat1) stdweight(stdist) matrix temp = e(b)',vecdiag(e(V))' nlcom _b[1]/_b[0], post matrix temp1=(1,0 \ e(b),e(V)) matrix temp=(temp,temp1) svy, subpop(if diab_m==1 & smoke_ever==`x'): ratio _d/py, stdize(agecat1) stdweight(stdist) matrix M=(M,(temp \ e(b),e(V),0,0 )) } if `x' == 2{ svy, subpop(if diab_m==1): ratio _d/py, over(normal) stdize(agecat1) stdweight(stdist) matrix temp = e(b)',vecdiag(e(V))' nlcom _b[1]/_b[0], post matrix temp1=(1,0 \ e(b),e(V)) matrix temp=(temp,temp1) svy, subpop(if diab_m==1): ratio _d/py, stdize(agecat1) stdweight(stdist) matrix M=(M,(temp \ e(b),e(V),0,0 )) } if `x'==0 { matrix big = M } else { matrix big = (big \ M) } } mat colnames big = cause smoke normal mx var rr rrvar matlist big drop _all svmat big,names(col) gen mx_sd = sqrt(var) gen mx_l = mx - 1.96*mx_sd gen mx_u = mx + 1.96*mx_sd gen rr_sd = sqrt(rrvar) gen rr_l = rr - 1.96*rr_sd gen rr_u = rr + 1.96*rr_sd drop mx_sd rr_sd var rrvar order cause smoke normal mx* rr* replace mx = mx*1000 replace mx_l = mx_l*1000 replace mx_u = mx_u*1000 export excel using "$tables\tablesraw.xlsx", sheet("raw t3") sheetreplace * TABLE 4 (Regression Models - Dysglycemia) * SPECIFICATION 1 clear use `temp', clear drop if smoke3 == . drop if edu_recode == . drop if hemo == . drop if startage >= censorage & diab_m == 1 gen subpop_d = diab_m == 1 svyset psu [pweight=sweight], strata(strata) stset censorage, id(seqn) failure(failure==1) enter(time startage) scale(12) if(subpop_d) tempfile master save `master', replace * MODEL 1 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 1") sheetreplace firstrow(varlabels) * MODEL 2 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo i.smoke3 normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 1") sheetmodify cell(G1) firstrow(varlabels) * MODEL 3 use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal normalXeversmoke" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 1") sheetmodify cell(M1) firstrow(varlabels) * NORMAL BMI COEFF IN EVER SMOKERS use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 nlcom _b[normal]+ _b[_IsmoXnor_1_1], post local t = _b[_nl_1]/_se[_nl_1] matrix p = 2*ttail(e(df_r),abs(`t')) matrix temp=(e(b),e(V),p[1,1]) mat colnames temp = par var pvalue drop _all svmat temp, names(col) gen par_se = sqrt(var) gen par_l = par - 1.96*par_se gen par_u = par + 1.96*par_se gen hr = exp(par) gen hr_l = exp(par_l) gen hr_u = exp(par_u) keep hr hr_l hr_u pvalue order hr hr_l hr_u pvalue export excel using "$tables\tablesraw.xlsx", sheet("raw t4 1") sheetmodify cell(S1) firstrow(varlabels) * SPECIFICATION 2 clear use `temp', clear drop if smoke3 == . drop if edu_recode == . drop if hemo == . drop if startage >= censorage & diab_m == 1 drop if dataset == 3 replace sweight = wtmec4yr if survey == 1 svyset psu [pweight=sweight], strata(strata) gen subpop_d = diab_m == 1 gen startage_excl = . replace startage_excl = startage + 3*12 stset censorage, id(seqn) failure(failure==1) enter(time startage_excl) scale(12) if(subpop_d) tempfile master save `master', replace * MODEL 1 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 2") sheetreplace firstrow(varlabels) * MODEL 2 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo i.smoke3 normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 2") sheetmodify cell(G1) firstrow(varlabels) * MODEL 3 use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal normalXeversmoke" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 2") sheetmodify cell(M1) firstrow(varlabels) * NORMAL BMI COEFF IN EVER SMOKERS use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 nlcom _b[normal]+ _b[_IsmoXnor_1_1], post local t = _b[_nl_1]/_se[_nl_1] matrix p = 2*ttail(e(df_r),abs(`t')) matrix temp=(e(b),e(V),p[1,1]) mat colnames temp = par var pvalue drop _all svmat temp, names(col) gen par_se = sqrt(var) gen par_l = par - 1.96*par_se gen par_u = par + 1.96*par_se gen hr = exp(par) gen hr_l = exp(par_l) gen hr_u = exp(par_u) keep hr hr_l hr_u pvalue order hr hr_l hr_u pvalue export excel using "$tables\tablesraw.xlsx", sheet("raw t4 2") sheetmodify cell(S1) firstrow(varlabels) * SPECIFICATION 3 clear use `temp', clear drop if smoke3 == . drop if edu_recode == . drop if hemo == . drop if startage >= censorage & diab_m == 1 drop if dataset == 3 drop if c_emphysema == 1 drop if c_cancer_smoking == 1 replace sweight = wtmec4yr if survey == 1 svyset psu [pweight=sweight], strata(strata) gen subpop_d = diab_m == 1 gen startage_excl = . replace startage_excl = startage + 3*12 stset censorage, id(seqn) failure(failure==1) enter(time startage_excl) scale(12) if(subpop_d) tempfile master save `master', replace * MODEL 1 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 3") sheetreplace firstrow(varlabels) * MODEL 2 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo i.smoke3 normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 3") sheetmodify cell(G1) firstrow(varlabels) * MODEL 3 use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal normalXeversmoke" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 3") sheetmodify cell(M1) firstrow(varlabels) * NORMAL BMI COEFF IN EVER SMOKERS use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 nlcom _b[normal]+ _b[_IsmoXnor_1_1], post local t = _b[_nl_1]/_se[_nl_1] matrix p = 2*ttail(e(df_r),abs(`t')) matrix temp=(e(b),e(V),p[1,1]) mat colnames temp = par var pvalue drop _all svmat temp, names(col) gen par_se = sqrt(var) gen par_l = par - 1.96*par_se gen par_u = par + 1.96*par_se gen hr = exp(par) gen hr_l = exp(par_l) gen hr_u = exp(par_u) keep hr hr_l hr_u pvalue order hr hr_l hr_u pvalue export excel using "$tables\tablesraw.xlsx", sheet("raw t4 3") sheetmodify cell(S1) firstrow(varlabels) * SPECIFICATION 4 clear use `temp', clear drop if smoke3 == . drop if edu_recode == . drop if hemo == . drop if startage >= censorage & diab_m == 1 drop if dataset == 3 drop if c_emphysema == 1 drop if c_cancer_smoking == 1 replace sweight = wtmec4yr if survey == 1 svyset psu [pweight=sweight], strata(strata) gen startage_excl = . replace startage_excl = startage + 3*12 /* gen sub_temp = diab_m == 1 stset censorage, id(seqn) failure(failure==1) enter(time startage_excl) scale(12) if(sub_temp) */ gen wc = bmi_m - bmi10 gen subpop_wc = diab_m == 1 & wc!=. & wc > -2.2 stset censorage, id(seqn) failure(failure==1) enter(time startage_excl) scale(12) if(subpop_wc) tempfile master save `master', replace * MODEL 1 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 4") sheetreplace firstrow(varlabels) * MODEL 2 use `master', clear xi: svy: stcox male hisp black i.edu_recode hemo i.smoke3 normal matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 4") sheetmodify cell(G1) firstrow(varlabels) * MODEL 3 use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 matrix temp=r(table) matrix temp1=(temp[1,1...] \ temp[4,1...] \ temp[5,1...] \ temp[6,1...])' matrix M=(temp1) matrix big = M mat colnames big = hr pval ll ul matlist big drop _all svmat big, names(col) gen name="" local i=1 local varname "male hisp black edu_1 edu_2 hemo smoke_1 smoke_2 smoke_3 smoke_4 smoke_5 smoke_6 normal normalXeversmoke" foreach v of local varname { replace name="`v'" in `i' local i=`i'+1 } order name export excel using "$tables\tablesraw.xlsx", sheet("raw t4 4") sheetmodify cell(M1) firstrow(varlabels) * NORMAL BMI COEFF IN EVER SMOKERS use `master', clear xi i.edu_recode i.smoke3 i.smoke_ever*i.normal svy: stcox male hisp black _Iedu_recod_1 _Iedu_recod_2 hemo _Ismoke3_1 _Ismoke3_2 _Ismoke3_3 _Ismoke3_4 _Ismoke3_5 _Ismoke3_6 normal _IsmoXnor_1_1 nlcom _b[normal]+ _b[_IsmoXnor_1_1], post local t = _b[_nl_1]/_se[_nl_1] matrix p = 2*ttail(e(df_r),abs(`t')) matrix temp=(e(b),e(V),p[1,1]) mat colnames temp = par var pvalue drop _all svmat temp, names(col) gen par_se = sqrt(var) gen par_l = par - 1.96*par_se gen par_u = par + 1.96*par_se gen hr = exp(par) gen hr_l = exp(par_l) gen hr_u = exp(par_u) keep hr hr_l hr_u pvalue order hr hr_l hr_u pvalue export excel using "$tables\tablesraw.xlsx", sheet("raw t4 4") sheetmodify cell(S1) firstrow(varlabels) ************end of program************** exit