*! version 6.0.0 11jan2000 program define streg1, eclass version 6 if `"`1'"'==`""' | substr(`"`1'"',1,1)==`","' { syntax [, Dist(string) *] if "`dist'"=="" { if "`e(cmd2)'" != "streg" { error 301 } Display `0' exit } } st_is 2 analysis syntax [varlist(default=empty)] [if] [in] /* */ [, CLuster(string) CMD Level(integer $S_level) /* */ Dist(string) hetero frailty ROBust /* */ TIme TR noHR noSHow * ] GetCmd `dist' local ecmd `s(cmd)' if "`frailty'"!="" | "`hetero'"!="" { if "`ecmd'"~="weibull" { di in red "frailty or hetero not valid with" /* */ " dist(`ecmd')" exit 198 } local ecmd="weibhet" local etime local otime } GetClass `ecmd' local class `s(class)' Opt_`class', `time' `tr' `hr' local etime `s(etime)' local otime `s(otime)' local rotime `s(rotime)' if `level' != $S_level { local otime `"level(`level') `otime'"' local rottime `"level(`level') `rotime'"' } /* obtain info from -st- */ local t0 "t0(_t0)" local d "dead(_d)" local id : char _dta[st_id] local w : char _dta[st_w] local wt : char _dta[st_wt] /* identify estimation subsample */ tempvar touse st_smpl `touse' `"`if'"' "`in'" "`cluster'" markout `touse' `varlist' /* determine command arguments */ if `"`wt'"'=="pweight" { local robust `"robust"' } if "`robust'"!="" & "`cluster'"=="" & "`id'"!="" { local cluster "`id'" } if "`cluster'"!="" { local cluster "cluster(`cluster')" } st_show `show' di if "`cmd'"!="" { di _n in gr `"-> `ecmd' _t `varlist' `w' `if' `in', "' /* */ `"`etime' `otime' `robust' `cluster' `t0' `d' `options'"' exit } if "`frailty'"!="" { local hetero "hetero" } `ecmd' _t `varlist' `w' if `touse', /* */ nocoef `etime' `robust' `cluster' `t0' `d' `options' if `class'==2 { est local frm2 "hazard" } else if `class'==3 { est local frm2 "time" } st_hc `touse' global S_E_cmd2 streg1 /* Double save */ est local cmd2 streg1 Display, `rotime' end program define Display syntax [, noHR TR *] if "`e(frm2)'" == "hazard" { if "`tr'"!="" { di in red "tr not allowed" exit 198 } if "`hr'"=="" { local hr "hr" } else local hr } else { if "`hr'"!="" { di in red "nohr not allowed" exit 198 } } di *Form Title st_hcd di `e(cmd)', `hr' `tr' `options' nohead end program define Title if "`e(frm2)'"=="hazard" { local h1 "log relative-hazard form" } else if "`e(frm2)'"=="time" { local h1 "accelerated failure-time form" } if "`e(cmd)'"=="weibull" { di in gr "Weibull regression -- `h1' " exit } if "`e(cmd)'"== "weibhet" { di in gr "Weibull regression with gamma heterogeneity -- `h1' " exit } if "`e(cmd)'"=="ereg" { di in gr "Exponential regression -- `h1' " exit } if "`e(cmd)'"=="lnormal" { di in gr "Log-normal regression -- `h1' " exit } if "`e(cmd)'"=="llogist" { di in gr "Log-logistic regression -- `h1' " exit } if "`e(cmd)'"=="gamma" { di in gr "Gamma regression -- `h1' " exit } if "`e(cmd)'"=="gompertz" { di in gr "Gompertz regression -- `h1' " exit } end program define GetCmd, sclass args dist if "`dist'"=="" { /* default command */ if "`e(cmd2)'"=="streg1" { sret local cmd "`e(cmd)'" exit } di in red "must specify distribution -dist()-" exit 198 } local l = length("`dist'") if substr("exponential",1,max(1,`l')) == "`dist'" { sret local cmd "ereg" exit } local l = length("`dist'") if substr("ereg",1,max(1,`l')) == "`dist'" { sret local cmd "ereg" exit } if substr("weibull",1,max(1,`l')) == "`dist'" { sret local cmd "weibull" exit } if substr("lognormal",1,max(`l',4)) == "`dist'" | /* */ substr("lnormal",1,max(`l',2)) == "`dist'" { sret local cmd "lnormal" exit } if substr("loglogistic",1,max(`l',4)) == "`dist'" | /* */ substr("llogistic",1,max(`l',2)) == "`dist'" { sret local cmd "llogist" exit } if substr("gompertz",1,max(3,`l')) == "`dist'" { sret local cmd "gompertz" exit } if substr("gamma",1,max(3,`l')) == "`dist'" { sret local cmd "gamma" exit } di in red "unknown distribution dist(`dist')" exit 198 end program define GetClass, sclass args cmd if "`cmd'"=="ereg" | "`cmd'"=="weibull" { sret local class 1 exit } if "`cmd'"=="gompertz" | "`cmd'"=="weibhet"{ sret local class 2 exit } if "`cmd'"=="lnormal" | "`cmd'"=="llogist" | "`cmd'"=="gamma" { sret local class 3 exit } error 301 end program define Opt_1, sclass syntax [, noHR TIme TR] if "`time'"!="" | "`tr'"!="" { sret local etime /*nothing*/ sret local otime `tr' sret local rotime `tr' } else { sret local etime hazard if "`hr'"=="" { sret local otime hr sret local rotime } else { sret local otime /*nothing*/ sret local rotime nohr } } end program define Opt_2, sclass syntax [, noHR] sret local etime /*nothing*/ if "`hr'"=="" { sret local otime hr sret local rotime /*nothing*/ } else { sret local otime sret local rotime nohr } end program define Opt_3, sclass syntax [, TIme TR] sret local etime /*nothing*/ sret local otime `tr' sret local rotime `tr' end exit Concerning GetClass returns s(class) 1 ln time/ln hazard command 2 ln hazard command 3 ln time command A class-1 command: 1) defaults to estimating results in ln time metric; a) reports coefficients by default b) the -tr- option will report coefficients as ratios 2) the -hazard- option will estimate in the ln hazard metric; a) reports coefficients by default b) the -hr- option will report coefficients as ratios; 3) A class-1 command fills in e(frm2) with "hazard" or "time" depending on metric. 4) e(t0) contains t0 variable or 0 Examples are -weibull- and -ereg- A class-2 command: 1) estimates in the ln hazard metric a) by default, reports coefficients b) the -hr- option will report coefficients as ratios 2) A class-2 command does NOT fill in e(frm2) 3) e(t0) contains t0 variable or 0 Examples are -gompertz- A class-3 command: 1) estimates in the ln time metric a) by default, reports coefficients b) the -tr- option will report coefficients as ratios 2) A class-3 command does NOT fill in e(frm2) 3) e(t0) contains t0 variable or 0 Examples are -lnormal-. -streg- works like this: 1) Estimates in the ln hazard metric if possible. a) reports coefficients as hazard ratios by default b) the -nohr- option will report coefficients c) estimates in ln time metric if option -time- is specified d) reports coefficients by default e) reports ratios if option -tr- 2) If only ln hazard is allowed: a) reports coefficients as hazard ratios by default b) the -nohr- option will report coefficients 3) If only ln time is allowed: a) may specify option -time- or not; it makes no difference d) reports coefficients by default c) reports ratios if option -tr- So, options are -nohr-, -time-, and -tr-. They map like this: Class 1: Est options Display options hazard hr nohr hazard time tr tr time tr tr Class 2: hr nohr Class 3: time tr tr time tr tr