*! _wkapm -- a version of kapmeier that allows weights. *! version 1.0.0 02/07/94 (STB-19: ssa3) program define _wkapm version 3.1 local options /* */ "BY(string) L1title(string) OFfset Symbol(string) Title(string) YLAbel(string) *" local varlist "req ex min(2) max(2)" local if "opt" local in "opt" local weight "iweight fweight aweight" parse "`*'" parse "`varlist'", parse(" ") local time "`1'" local died "`2'" if "`l1title'"=="" { local l1title "Survival Probability" } if "`title'"=="" { local title " Kaplan-Meier Survival Curve" } if "`offset'"=="" { local myaxis "noaxis xline(0) yline(0)" } if "`ylabel'"=="" { local ylabel "ylab(0,.25,.5,.75,1)" } else if "`ylabel'"=="." { local ylabel } else local ylabel "ylabel(`ylabel')" if ("`weight'"!="") { tempvar wt gen float `wt' `exp' local weight "[`weight'=`wt']" } if "`symbol'"=="" { local symbol "STD" } tempvar grp sc GRPN preserve quietly { if "`if'`in'"~="" { keep `if' `in' } drop if `time'==. | `died'==. keep `time' `died' `by' `wt' _crcwsrv `time' `died' `by' `weight' by `by' `time': keep if _n==_N summarize `time' local MIN = min(_result(5),0) local NN = _N+1 set obs `NN' /* fake t=0 point */ replace `time'=`MIN'-100 if _n==_N replace _surv=1 if _n==_N replace `died'=1 if _n==_N /* not censored */ if "`by'"!="" { summarize `by' replace `by'=_result(5) if _n==_N drop if `by'==. sort `by' `time' replace `time' = `MIN' if _n==1 by `by': gen long `grp' = (_n==1) replace `grp' = sum(`grp') local group 1 local t : type `by' while `group'<=`grp'[_N] { tempvar gsc gpp gen byte `sc'=(_n==1 | `group'==`grp') gen `gsc'=_surv if `sc' gen `t' `GRPN'=`by' if `sc' replace `GRPN'=`GRPN'[_n-1] if !`sc' local temp=`GRPN'[_N] label var `gsc' "Group `temp'" gen str2 `gpp'=" " replace `gpp'="`temp'" if `died'==0 /* */ & "`symbol'"=="STD" local vlist "`vlist' `gsc'" local syms "`syms'[`gpp']" local connect "`connect'J" drop `sc' `GRPN' local group = `group'+1 } format `vlist' %9.2f #delimit ; noisily graph `vlist' `time', c(`connect') title("`title'") `ylabel' s(`syms') l1("`l1title'") xsca(0,.) `myaxis' `options'; #delimit cr } else { sort `time' replace `time' = `MIN' if _n==1 gen str1 _pp=" " replace _pp="x" if `died'==0 & "`symbol'"=="STD" format _surv %9.2f #delimit ; noisily graph _surv `time', s([_pp]) c(J) ti("`title'") xsca(0,.) `ylabel' l1("`l1title'") `myaxis' `options' ; #delimit cr } } end