Dear all,
I am examining interactions between BMI (z-score) and education (3 levels). In doing so, I have constructed three rc splines, one for each level of education. The reference is medium level of education and BMI z-score=0. I would like to add confidence intervals to the graph in order to see how much they overlap. Does anyone know if it's possible? And if so, how is it done?
Here is the code with additional notes:
{
preserve
rc_spline zc_bmi, nknots(5)
foreach var of varlist _S* { // create corresponding interaction variables
gen `var'eduter_2=`var'*i_eduter_2
gen `var'eduter_3=`var'*i_eduter_3
}
* - Cox-regression survival analyses
stset ageout, failure(case==1) enter(agein) id(id) // survival analyses settings
stcox _Szc_bmi1 _Szc_bmi2 _Szc_bmi3 _Szc_bmi4 i_eduter_2 i_eduter_3 _Szc_bmi?eduter_2 _Szc_bmi?eduter_3 c1_bpp zc_height, str(bkoh) // running Cox-regression analyses
foreach var of varlist c1_bpp zc_height{ // adjustment variables to constant (zero) influence on predictions
replace `var'=0
}
predict b, hr // derive preliminary HRs
sort eduter zc_bmi // identify reference point (BMI=25, EDU=2; through indicator)
gen ref=(zc_bmi>=0.0 & eduter==2) | eduter==3
tab ref eduter
gen bref=b if ref[_n]>ref[_n-1] // derive current HR at reference
summ bref
local bref=r(mean)
display "HR-ref (BMI=0 & EDU==2): `bref'"
replace b=b/`bref' // scale so that reference corresponds to HR=1
* - Graphing results
summ zc_bmi, det
bysort eduter: summ zc_bmi, det // look at percentiles
keep if inrange(zc_bmi,-2.0,2.0) // to avoid too much extrapolation
twoway
(line b zc_bmi if eduter==1, lcolor(black) lpattern(solid))
(line b zc_bmi if eduter==2, lcolor(black) lpattern(dash))
(line b zc_bmi if eduter==3, lcolor(black) lpattern(dot))
,
aspectratio(1)
xsize(4)
xtitle("BMI z-score", size(*1.1))
xscale(range(-2.0 2.0))
xlabel(-2.0 -1.0 0 1.0 2.0, tlcolor(black) labcolor(black) labsize(*0.8))
ytitle("HR", size(*1.1))
ysize(4)
yscale(log)
ylabel(0.70 "0.70" 2 "2" 3 "3" 4 "4", angle(horizontal) labsize(*0.8) tlcolor(black) labcolor(black))
yline(1,lwidth(medium) lcolor(black))
title("")
legend(subtitle("Education:", size(*0.5)) order(1 "Short" 2 "Medium" 3 "Long") cols(1) ring(0) bplacement(sc) bmargin(tiny) region(lstyle(none) fcolor(white)) symxsize(*0.5) symysize(*0.5) textwidth(*0.5) size(*0.5))
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
restore
}
Any help/comments are much appreciated!
Thanks in advance.
Best regards,
Alice
I am examining interactions between BMI (z-score) and education (3 levels). In doing so, I have constructed three rc splines, one for each level of education. The reference is medium level of education and BMI z-score=0. I would like to add confidence intervals to the graph in order to see how much they overlap. Does anyone know if it's possible? And if so, how is it done?
Here is the code with additional notes:
{
preserve
rc_spline zc_bmi, nknots(5)
foreach var of varlist _S* { // create corresponding interaction variables
gen `var'eduter_2=`var'*i_eduter_2
gen `var'eduter_3=`var'*i_eduter_3
}
* - Cox-regression survival analyses
stset ageout, failure(case==1) enter(agein) id(id) // survival analyses settings
stcox _Szc_bmi1 _Szc_bmi2 _Szc_bmi3 _Szc_bmi4 i_eduter_2 i_eduter_3 _Szc_bmi?eduter_2 _Szc_bmi?eduter_3 c1_bpp zc_height, str(bkoh) // running Cox-regression analyses
foreach var of varlist c1_bpp zc_height{ // adjustment variables to constant (zero) influence on predictions
replace `var'=0
}
predict b, hr // derive preliminary HRs
sort eduter zc_bmi // identify reference point (BMI=25, EDU=2; through indicator)
gen ref=(zc_bmi>=0.0 & eduter==2) | eduter==3
tab ref eduter
gen bref=b if ref[_n]>ref[_n-1] // derive current HR at reference
summ bref
local bref=r(mean)
display "HR-ref (BMI=0 & EDU==2): `bref'"
replace b=b/`bref' // scale so that reference corresponds to HR=1
* - Graphing results
summ zc_bmi, det
bysort eduter: summ zc_bmi, det // look at percentiles
keep if inrange(zc_bmi,-2.0,2.0) // to avoid too much extrapolation
twoway
(line b zc_bmi if eduter==1, lcolor(black) lpattern(solid))
(line b zc_bmi if eduter==2, lcolor(black) lpattern(dash))
(line b zc_bmi if eduter==3, lcolor(black) lpattern(dot))
,
aspectratio(1)
xsize(4)
xtitle("BMI z-score", size(*1.1))
xscale(range(-2.0 2.0))
xlabel(-2.0 -1.0 0 1.0 2.0, tlcolor(black) labcolor(black) labsize(*0.8))
ytitle("HR", size(*1.1))
ysize(4)
yscale(log)
ylabel(0.70 "0.70" 2 "2" 3 "3" 4 "4", angle(horizontal) labsize(*0.8) tlcolor(black) labcolor(black))
yline(1,lwidth(medium) lcolor(black))
title("")
legend(subtitle("Education:", size(*0.5)) order(1 "Short" 2 "Medium" 3 "Long") cols(1) ring(0) bplacement(sc) bmargin(tiny) region(lstyle(none) fcolor(white)) symxsize(*0.5) symysize(*0.5) textwidth(*0.5) size(*0.5))
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
plotregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
restore
}
Any help/comments are much appreciated!
Thanks in advance.
Best regards,
Alice