/*************************************************************************** This code available at: http://pauldickman.com/software/stata/competing-risks-stcompadj.do Illustration of stcompadj using the example from the help file. Data were extracted from the R mstate package using following code library(mstate) library(survival) library(foreign) data("aidssi", package= "mstate") write.dta(aidssi, "aidssi.dta") Dependencies ssc install stcompadj ssc install stpm2 net install gr0002_3 (for the lean2 theme) Paul Dickman, May 2021 *******************************************************************************/ use https://pauldickman.com/data/aidssi.dta, clear // recode ccr5 to correspond with the example in the -stcompadj- help file generate ccr=ccr5-1 stset time, f(status==1) stcompadj ccr=0 , compet(2) maineffect(ccr) competeffect(ccr) gen(Main0 Compet0) stcompadj ccr=1 , compet(2) maineffect(ccr) competeffect(ccr) gen(Main1 Compet1) twoway line Main0 Main1 _t, sort c(J J) scheme(lean2) /// xti("Years from HIV Infection") yti("Cumulative Incidence") /// yla(0(.1).5,glp(shortdash)) xla(0(2)12) name(AIDS,replace) /// legend(pos(11) ring(0) label(1 "WW") label(2 "WM")) ti("AIDS") twoway line Compet0 Compet1 _t if _t<13.5, sort c(J J) scheme(lean2) /// xti("Years from HIV Infection") yti("Cumulative Incidence") /// yla(0(.1).5,glp(shortdash)) xla(0(2)12) name(SI,replace) /// legend(pos(11) ring(0) label(1 "WW") label(2 "WM")) ti("SI Appearance") // repeat using flexible parametric models (rather than the default Cox model) drop Main0 Main1 Compet0 Compet1 stcompadj ccr=0 , compet(2) maineffect(ccr) competeffect(ccr) gen(Main0 Compet0) flexible stcompadj ccr=1 , compet(2) maineffect(ccr) competeffect(ccr) gen(Main1 Compet1) flexible twoway line Main0 Main1 _t, sort c(J J) scheme(lean2) /// xti("Years from HIV Infection") yti("Cumulative Incidence") /// yla(0(.1).5,glp(shortdash)) xla(0(2)12) name("AIDS_stpm2",replace) /// legend(pos(11) ring(0) label(1 "WW") label(2 "WM")) ti("AIDS") twoway line Compet0 Compet1 _t if _t<13.5, sort c(J J) scheme(lean2) /// xti("Years from HIV Infection") yti("Cumulative Incidence") /// yla(0(.1).5,glp(shortdash)) xla(0(2)12) name("SI_stpm2",replace) /// legend(pos(11) ring(0) label(1 "WW") label(2 "WM")) ti("SI Appearance")