📄 zts_5.ado
字号:
di in gr %6.0g `t'[`i'] " " in ye /*
*/ %11.4f `s'[`i']
}
local i = `i'+1
}
di in gr _dup(`dupcnt') "-"
if "`adjustf'" != "" {
di in gr "`ttl' function adjusted for `adjustf'"
}
end
program define GetVal /* grpvar g# var maxlen */
local grp "`1'"
local g "`2'"
local v "`3'"
local maxlen "`4'"
tempvar obs newv
quietly {
gen long `obs' = _n if `grp'==`g'
summ `obs'
local j = _result(5)
local typ : type `v'
local val = `v'[`j']
global S_2
if substr("`typ'",1,3)!="str" {
local lbl : value label `v'
if "`lbl'" != "" {
local val : label `lbl' `val'
}
else global S_2 "`v'="
}
global S_1 = substr(trim("`val'"),1,`maxlen')
}
end
program define sts_sh /* grp g# <byvars> */
local grp "`1'"
local g "`2'"
local by "`3'"
parse "`by'", parse(" ")
global S_3
while "`1'" != "" {
GetVal `grp' `g' `1' 20
global S_3 "$S_3$S_2$S_1 "
* di in gr "$S_2$S_1 " _c
mac shift
}
* di
end
program define Reat /* t <processed at-list> */
if "`2'"!="reat" {
global S_1
exit
}
quietly {
local t "`1'"
local n = `3'
local n = cond(`n'-2<1, 1, `n'-2)
qui summ `t' if `t'!=0
local tmin = _result(5)
local tmax = _result(6)
local dt = (`tmax' -`tmin')/`n'
if `dt'>=1 {
local dt = int(`dt')
}
global S_1
local v = int(`tmin')
while `v' < `tmax' {
global S_1 "$S_1 `v'"
local v = `v' + `dt'
}
global S_1 "$S_1 `v'"
}
end
program define Procat /* at-list */
parse "`*'", parse(" ;:,")
local i : word count `*'
if `i'==1 {
capture confirm integer numb `*'
if _rc == 0 {
capture assert `*' >= 1
}
if _rc {
di in red "at(`*') invalid"
exit 198
}
global S_1 "reat `*'"
exit
}
local i 1
while "``i''" != "" {
if "``i''" == "," {
local `i' " "
}
local i=`i'+1
}
capture noisily Procatu `*'
if _rc {
di in red "at() invalid"
exit _rc
}
end
program define Procatu /* at-list */
while "`1'" != "" {
if "`1'"==":" | "`1'"==";" | "`1'"=="..." | "`1'"==".." {
if "`l0'"=="" | "`2'"=="" { exit 198 }
mac shift
local cnt 1
}
else local cnt 0
capture confirm number `1'
if _rc { exit 198 }
if "`l1'" != "" {
if `1'<=`l1' { exit 198 }
}
if `cnt' {
local d = `l1'-`l0'
local i = `l1'+`d'
while `i' <= `1' {
local l0 `l1'
local l1 `i'
local list "`list' `i'"
local i=`i'+`d'
}
}
else {
local l0 `l1'
local l1 `1'
local list "`list' `1'"
}
mac shift
}
global S_1 "`list'"
end
program define Listata
local by "`1'"
local grp "`2'"
local t "`3'"
local s "`4'"
local at "`5'"
local ttl "`6'"
local blnk "`7'"
local adjustf "`8'"
if "`by'"!="" {
local byp "by `by':"
}
di in gr _n " Adjusted"
di in gr " Time `blnk'`ttl' Function" _n _dup(29) "-"
if "`grp'"=="" {
tempvar grp
qui gen byte `grp' = 1
local ngrp 1
}
else {
qui summ `grp'
local ngrp = _result(6)
}
parse "`at'", parse(" ")
tempvar obs
local g 1
while `g' <= `ngrp' {
/* set i0, i1: bounds of group */
qui gen long `obs' = _n if `grp'==`g'
qui summ `obs'
local i0 = _result(5)
local i1 = _result(6)
drop `obs'
if "`by'" != "" {
sts_sh `grp' `g' "`by'"
di in gr "$S_3"
}
local j 1
while "``j''" != "" {
qui gen long `obs' = _n if `t'>``j'' in `i0'/`i1'
qui summ `obs'
local i = cond(_result(5)>=.,`i1',_result(5)-1)
drop `obs'
if `i'<`i0' {
di in gr %8.0g ``j'' " " in ye /*
*/ %11.4f 1
}
else if `i'==`i1' & ``j''>`t'[`i1'] {
di in gr %8.0g ``j'' " " in ye /*
*/ %11.4f .
}
else {
di in gr %8.0g ``j'' " " in ye /*
*/ %11.4f `s'[`i']
}
local j=`j'+1
}
local g=`g'+1
}
di in gr _dup(29) "-" _n "`ttl' function adjusted for `adjustf'"
end
program define Listat
local by "`1'"
local grp "`2'"
local t "`3'"
local n "`4'"
local d "`5'"
local cens "`6'"
local ent "`7'"
local s "`8'"
local se "`9'"
local lb "`10'"
local ub "`11'"
local at "`12'"
local level "`13'"
local ttl "`14'" /* "Survival" or " Failure" */
if "`by'"!="" {
local byp "by `by':"
}
quietly {
`byp' replace `d'=sum(`d')
`byp' replace `cens'=sum(`cens')
`byp' replace `ent' = sum(`ent')
}
di in gr _n _col(15) "Beg." /*
*/ _col(41) "`ttl'" _col(55) "Std." _n /*
*/ " Time Total Fail" /*
*/ _col(41) "Function Error [`level'% Conf. Int.]" _n /*
*/ _dup(79) "-"
if "`grp'"=="" {
tempvar grp
qui gen byte `grp' = 1
local ngrp 1
}
else {
qui summ `grp'
local ngrp = _result(6)
}
parse "`at'", parse(" ")
tempvar obs
local g 1
while `g' <= `ngrp' {
/* set i0, i1: bounds of group */
qui gen long `obs' = _n if `grp'==`g'
qui summ `obs'
local i0 = _result(5)
local i1 = _result(6)
drop `obs'
if "`by'" != "" {
sts_sh `grp' `g' "`by'"
di in gr "$S_3"
}
local lfail 0
local j 1
while "``j''" != "" {
qui gen long `obs' = _n if `t'>``j'' in `i0'/`i1'
qui summ `obs'
local i = cond(_result(5)>=.,`i1',_result(5)-1)
drop `obs'
if `i'<`i0' {
di in gr %8.0g ``j'' " " in ye /*
*/ /*
*/ %8.0g 0 " " /*
*/ %8.0g 0 " " /*
*/ _skip(8) /*
*/ %11.4f 1 " " /*
*/ %9.4f . " " /*
*/ %10.4f . " " /*
*/ %9.4f .
}
else if `i'==`i1' & ``j''>`t'[`i1'] {
local ifail = `d'[`i'] - `lfail'
local lfail = `d'[`i']
di in gr %8.0g ``j'' " " in ye /*
*/ /*
*/ %8.0g `n'[`i'] " " /*
*/ %8.0g `ifail' " " /*
*/ _skip(8) /*
*/ %11.4f . " " /*
*/ %9.4f . " " /*
*/ %10.4f . " " /*
*/ %9.4f .
}
else {
local ifail = `d'[`i'] - `lfail'
local lfail = `d'[`i']
di in gr %8.0g ``j'' " " in ye /*
*/ /*
*/ %8.0g `n'[`i'] " " /*
*/ %8.0g `ifail' " " /*
*/ _skip(8) /*
*/ %11.4f `s'[`i'] " " /*
*/ %9.4f `se'[`i'] " " /*
*/ %10.4f `lb'[`i'] " " /*
*/ %9.4f `ub'[`i']
}
local j=`j'+1
}
local g=`g'+1
}
di in gr _dup(79) "-"
#delimit ;
di in gr
"Note: `ttl' function is calculated over full data and evaluated at" _n
" indicated times; it is not calculated from aggregates shown at left.";
#delimit cr
end
program define Licomp
local mark "`1'"
local by "`2'"
local grp "`3'"
local t "`4'"
local s "`5'"
local at "`6'"
local failure "`7'" /* "failure" or "" */
local adjustf "`8'"
qui summ `grp'
local ngrp = _result(6)
local ng 1
while `ng' <= `ngrp' {
local nglast=min(`ng'+5,`ngrp')
Licompu "`mark'" "`by'" "`grp'" `t' `s' "`at'" `ng' `nglast' /*
*/ "`failure'" "`adjustf'"
local ng=`ng'+6
}
if "`adjustf'"!="" {
if "`failure'"=="" {
local ttl "Survivor"
}
else local ttl "Failure"
di in gr "`ttl' function adjusted for `adjustf'"
}
end
program define Licompu
local by "`2'"
local grp "`3'"
local t "`4'"
local s "`5'"
local at "`6'"
local g0 `7'
local g1 `8'
local failure "`9'" /* "failure" or "" */
local adjustf "`10'"
di
if "`failure'"=="" {
local ttl "Survivor"
}
else local ttl "Failure"
if "`adjustf'" != "" {
local ttl "Adjusted `ttl'"
}
local ttl "`ttl' Function"
local tl = length("`ttl'")
local wid = (`g1'-`g0'+1)*11-5
local ldash = int((`wid' - `tl')/2)
local rdash = `wid' - `tl' - `ldash'
if `ldash'>0 & `rdash'>0 {
di in gr _col(18) _dup(`ldash') "-" "`ttl'" _dup(`rdash') "-"
}
else {
local skip = max(17 + `wid' - `tl', 0)
di in gr _skip(`skip') "`ttl'"
}
parse "`by'", parse(" ")
while "`1'" != "" {
di in gr "`1'" _col(13) _c
local g `g0'
while `g' <= `g1' {
GetVal `grp' `g' `1' 9
local skip = 11 - length("$S_1")
di in gr _skip(`skip') "$S_1" _c
* di in gr "12" %9.0g 1 _c
local g = `g'+1
}
di
mac shift
}
local ndash = 12+(`g1'-`g0'+1)*11
di in gr _dup(`ndash') "-"
tempvar obs
parse "`at'", parse(" ")
local j 1
local thead "time"
while "``j''" != "" {
di in gr "`thead'" %8.0g ``j'' _c
local thead " "
local g `g0'
while `g'<=`g1' {
qui gen long `obs' = _n if `grp'==`g'
qui summ `obs'
local i0 = _result(5)
local i1 = _result(6)
drop `obs'
qui gen long `obs' = _n if `t'>``j'' in `i0'/`i1'
qui summ `obs'
local i = cond(_result(5)>=.,`i1',_result(5)-1)
drop `obs'
if `i'<`i0' {
local res 1
}
else if `i'==`i1' & `t'[`i']!=``j'' {
local res .
}
else local res = `s'[`i']
di in ye %11.4f `res' _c
local g=`g'+1
}
di
local j=`j'+1
}
di in gr _dup(`ndash') "-"
end
program define Graph
local if "opt"
local in "opt"
local options "ADjustfor(string) noBorder BY(string) Enter Failure Gwood noLAbel Level(integer $S_level) LOST noORIgin SEParate noSHow STrata(string) T1title(string) T2title(string) TMIn(real -1) TMAx(real -1) TRim(integer 32) XASis XLAbel(string) YASis YLAbel(string) YLOg ATRisk *"
parse "`*'"
local t : char _dta[st_t]
local t0 : char _dta[st_t0]
local d : char _dta[st_d]
local id : char _dta[st_id]
local w : char _dta[st_w]
if `level'<10 | `level'>99 {
di in red "level() invalid"
exit 198
}
if "`gwood'"!="" {
local wt : char _dta[st_wt]
if "`wt'"=="pweight" {
di in red "option gwood not allowed with pweighted data"
exit 198
}
local wt
}
ByStAdj "`by'" "`strata'" "`adjustf'"
local by "$S_1"
local strata "$S_2"
local adjustf "$S_3"
local sb "$S_4"
if "`sb'" == "" { local label "nolabel" }
else {
local n : word count `sb'
if `n'>1 { local label "nolabel" }
if `n'>1 & ("`separat'"!="" | "`gwood'"!="") {
di in red "may not specify " _c
if "`separat'"!="" {
di in red "separate" _c
}
else di in red "gwood" _c
di in red " with more than one by/strata variable."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -