*! version 2.0 dgc/mh Sep 1997 STB-41 ssa10.1 program define sttody version 5.0 st_is local varlist "req new min(2) max(3)" local options "BY(string) FCodes(string) SCale(real 1)" parse "`*'" parse "`varlist'", parse(" ") local d "`1'" local y "`2'" if "`by'"!="" { confirm ex var `by' } di in gr "Derive failure counts and person-time from st data" st_show if "`fcodes'"!="" { di di in gr " failure codes: " in ye "`fcodes'" } local id : char _dta[st_id] local f : char _dta[st_d] local t : char _dta[st_t] local t0 : char _dta[st_t0] local weight : char _dta[st_wt] local wt : char _dta[st_wv] if "`weight'"!="" { di in gr "`weight's are used" } quietly { if "`fcodes'"=="" { replace `d' = (`f'!=0) } else { replace `d' = `f' recode `d' `fcodes' = 1 * = 0 } if "`t0'"=="" { replace `y' = `t' } else { replace `y' = `t' - `t0' } if `scale'!=1 { replace `y' = `y'/`scale' } if "`wt'"!="" { replace `d' = `d'*`wt' replace `y' = `y'*`wt' } if "`id'"!="" { sort `id' `by' `t' tempvar mult by `id' `by': gen byte `mult' = (_N>1 & _n==_N) qui count if `mult' local clps = _result(1) if `clps'>0 { by `id' `by': replace `d' = sum(`d') by `id' `by': replace `y' = sum(`y') by `id' `by': replace `d' = `d'[_N] if _n==1 by `id' `by': replace `y' = `y'[_N] if _n==1 by `id' `by': keep if _n==1 noi di noi di in bl "Warning: data set collapsed into " in ye _N /* */ in gr " records" noi di in bl _col(3) "- all variables set to their earliest value" noi di in bl _col(3) "- definition of st data cleared" stset , clear } } } end