program define survtab version 2.1 if "%_*"=="" { di in red "invalid syntax -- see help survcurv" exit 198 } mac def _varlist "req ex" mac def _options "BY(string) AT(string)" mac def _if "opt" mac def _in "opt" parse "%_*" parse "%_varlist", parse(" ") if "%_at"=="" { di in red "Specify the time points for calculation of S" di in red "through inclusion of the at(t1[,t2[,t3..]]) option." di in yellow "Example: survtab surv fail,by(group) at(24,60)." di in yellow " 24 and 60 are the time points." exit } _crcsrv2 %_1 %_2 %_by %_in %_if mac def _rc = _rc capture drop _TIME capture drop _PRINT macro define _POINT " recode( %_1 , %_at , 9999) " quietly gen int _TIME = %_POINT quietly replace _atrisk=-_atrisk sort %_by _TIME %_1 _atrisk quietly by %_by _TIME : gen byte _PRINT=1 if _n==_N&_TIME~=9999 quietly replace _atrisk=-_atrisk format _atrisk _TIME %_by %8.0f format _surv _stds %8.3f noisily list %_by _TIME _atrisk _surv _stds if _PRINT==1 exit %_rc end