*! version 1.0.2 JMGarrett 19Feb98 STB-44 ssa12 /* Graph adjusted Kaplan-Meier survivor function by categories of X */ /* Form: stkap, by(xvars) adj(covariates) options */ /* Must have stset data before using this command */ program define stkap version 5.0 st_is #delimit ; local options "BY(string) STRata(string) ADJust(string) *" ; #delimit cr local if "opt" parse "`*'" if "`strata'"~="" & "`adjust'"=="" { disp in red "strata() requires adjust(); perhaps you mean by()" disp in blue "r(198);" exit } preserve local t: char _dta[st_t] local d: char _dta[st_d] local t0: char _dta[st_t0] local id: char _dta[st_id] capture keep `if' quietly drop if `t'==. | `d'==. * If there are by() variables, drop obs. with missing values parse "`by'", parse(" ") if "`1'"~="" {local byvar="Y"} while "`1'"~="" { quietly drop if `1'==. macro shift } * If there are strata() variables, drop obs. with missing values parse "`strata'", parse(" ") if "`1'"~="" {local strtvar="Y"} while "`1'"~="" { quietly drop if `1'==. macro shift } * If there are covariates, drop missing, center or use specified values parse "`adjust'", parse(" ") local numcov=0 local i=1 while "`1'"~="" { local equal=index("`1'","=") if `equal'==0 { local cov`i'="`1'" local mcov`i'="mean" } if `equal'~=0 { local cov`i'=substr("`1'",1,`equal'-1) local mcov`i'=substr("`1'",`equal'+1,length("`1'")) } quietly drop if `cov`i''==. local covlist `covlist' `cov`i'' local i=`i'+1 macro shift local numcov=`i'-1 } local i=1 while `i'<=`numcov' { if "`mcov`i''"=="mean" { quietly sum `cov`i'' quietly replace `cov`i''=`cov`i''-_result(3) } if "`mcov`i''"~="mean" { quietly replace `cov`i''=`cov`i''-`mcov`i'' } local i=`i'+1 } * Graph KM if "`byvar'"=="" & "`strtvar'"=="" & `numcov'==0 { sts graph, `options' } if "`byvar'"=="Y" & "`strtvar'"=="" & `numcov'==0 { sts graph, by(`by') `options' } if "`byvar'"=="" & "`strtvar'"=="" & `numcov'>0 { sts graph, adjust(`covlist') `options' } if "`byvar'"=="Y" & "`strtvar'"=="" & `numcov'>0 { sts graph, by(`by') adjust(`covlist') `options' } if "`byvar'"=="" & "`strtvar'"=="Y" & `numcov'>0 { sts graph, strata(`strata') adjust(`covlist') `options' } end