*! Calculates life tables and related graphs: v1.00 August 2000 (STB-59: ssa14) *! This program is no more than a sub-routine called by lifetabl.ado *! whenever it is necessary to analyse multiple causes of death. *! Author: C.Ramalheira, cramal@ci.uc.pt *! Coimbra Faculty of Medicine & University Hospital cap program drop lifetabs program define lifetabs, nclass version 6.0 syntax [varlist] [if] [in] , Strata(varname) [ Rates(varname) Multip(string) /* */ Keep Deaths(varname) Pop(varname) BY(varname) RADIX(int 100000) /* */ Weights(numlist min=1 max=4 >0 <1) Label(varname) NOT SAVing(string) /* */ NYears(varname) GE GP GS GH GSC GRPHS SClist(varlist min=1 max=20) REPLACE /* */ LOGrate NOO ALLRx SCOnly PYLL(numlist >20 <=100 max=1) ALLSCT /* */ LEVel(numlist >20 <=100 max=1) CI NOYLL * ] tokenize "`varlist'" if "$warn"=="" { lifetabl `0' exit } tempvar touse mark `touse' `if' `in' set display line 100 if "`level'"=="" { local level = "95" } if "`level'"~="" { global D_level = "`level'" } local zscore = -invnorm( (1-($D_level/100))/2 ) local nrows = "$nrows" local noYLL = "$noYLL" local max = "$max" local factor = "$factor" local yearmsg = "$yearmsg" if "`label'"=="" { local label = "$lbl" } local lab = "$lab" local fake = "$fake" if "`gsc'"=="" { local gsc = "$gsc" } if "`pyll'"=="" { local pyll = "65" } if "`pyll'"~="" { local pyll = round(`pyll',1) } local WW = "$WW" local w1 = "$w1" local w2 = "$w2" local w3 = "$w3" local w4 = "$w4" local A = "`strata'" if "`label'"~="" { tempvar Labv qui ge str7 `Labv' = substr(`label',1,7) qui label var `Labv' "`label'" local labv : variable label `Labv' } if "`nyears'"=="" { tempvar nyears qui ge `nyears' = 1 local nyears = "`nyears'" } if "`pop'" ~= "" { local P = "`pop'" } if "`deaths'" ~= "" { local D = "`deaths'" } if "`deaths'" == "" & "`allrx'"=="" { tempvar Dx qui egen `Dx' = rsum(`sclist') label var `Dx' "Deaths: pop=sum(sclist)" local D = "`Dx'" } if "`rates'" ~= "" { local R = "`rates'" } if "`rates'" == "" { local R = "_Rx" } local numvars : word count `sclist' if `numvars'==1 { local sclist = "`sclist' " + "_OtherSC" } local numvars : word count `sclist' tokenize "`sclist'", parse(" ") local t 1 while `t'<=`numvars' { local var`t' = "``t''" tempvar _Dx`t' _qx`t' _dx`t' _Dxd`t' Wx`t' Fx`t' if "`allrx'"~="" { if "`pop'" ~= "" { qui ge `_Dx`t'' = ((`var`t''*$factor)/100000)*`pop' if `t'==1 { tempvar Dx qui ge `Dx' = (_Rx/100000)*`pop' label var `Dx' "TDeaths: pop=pop" local D = "`Dx'" } } if "`pop'" == "" { if "`deaths'" == "" { tempvar pop qui ge `pop' = `radix' local P = "`pop'" qui ge `_Dx`t'' = ((`var`t''*$factor)/100000)*`pop' if `t'==1 { tempvar Dx qui ge `Dx' = (_Rx/100000)*`pop' label var `Dx' "TDeaths: pop=radix" local D = "`Dx'" } local noYLLx = "yes" } if "`deaths'" ~= "" { qui ge `_Dx`t'' = ((`var`t''*$factor)/_Rx)*`deaths' tempvar pop if "`rates'"~="" { qui gen `pop' = `deaths'/((`rates'*$factor)/100000) } else { qui gen `pop' = `deaths'/(_Rx/100000) } local P = "`pop'" } } } if "`allrx'"=="" { if "`pop'" ~= "" { qui ge `_Dx`t'' = `var`t'' } if "`pop'" == "" { if "`deaths'" == "" { qui ge `_Dx`t'' = `var`t'' if `t'==1 { tempvar Dx qui egen `Dx' = rsum(`sclist') label var `Dx' "TDeaths: pop=sum" local D = "`Dx'" local deaths = "`Dx'" } } if "`deaths'" ~= "" { tempvar pop if "`rates'"~="" { qui gen `pop' = `deaths'/((`rates'*$factor)/100000) } else { qui gen `pop' = `deaths'/(_Rx/100000) } local P = "`pop'" } } } label var `_Dx`t'' "`var`t'': _Dx`t'" qui ge `_qx`t'' = (`_Dx`t''/`D')*_qx * qui replace `_qx`t'' = round(`_qx`t'',0.0001) label var `_qx`t'' "`var`t'': _qx`t'" qui ge `_dx`t'' = _lx * `_qx`t'' label var `_dx`t'' "`var`t'': _dx`t'" qui ge `_Dxd`t'' = `D'-`_Dx`t'' label var `_Dxd`t'' "TotDeaths - `var`t''" qui format `_Dx`t'' `_dx`t'' %6.0f qui format `_qx`t'' %6.5f tempvar zz xx qui egen `xx' = group(`A') if `touse'==1 qui gen `zz' = sum(`_dx`t'') qui gen `Wx`t'' =. qui replace `Wx`t'' = `zz'[_N] if `xx'==1 local Wx0`t' = `zz'[_N] qui format `Wx`t'' %6.0f qui replace `zz' = `_dx`t'' local w 2 while `w'<=$max { local f = `w' - 1 qui replace `zz' =. in 1/`f' qui replace `zz' = sum(`zz') qui replace `Wx`t'' = `zz'[_N] in `w' qui replace `zz' = `_dx`t'' local w = `w' + 1 } qui ge `Fx`t'' = 1-(`Wx`t''/`Wx0`t'') local Wlst = "`Wlst' " + "`Wx`t''" local Flst = "`Flst' " + "`Fx`t''" qui format `Fx`t'' %6.5f * l _lx `_qx`t'' `_dx`t'' `Wx`t'' `Fx`t'' local lpd`t' = `Wx0`t''/`radix' local t = `t' + 1 } tempvar sW sF qui egen `sW' = rsum(`Wlst') qui gen `sF' = 1-_Surv local t 1 while `t'<=`numvars' { tempvar sW`t' sF`t' qui gen `sW`t'' = `Wx`t''/`sW' qui gen `sF`t'' = 1-`Fx`t'' local sWlst = "`sWlst' " + "`sW`t''" local sFlst = "`sFlst' " + "`sF`t''" local t = `t' + 1 } * ----------------- * Geração de pontos definidores dos intervalos quietly { tempvar pm pmx gen `pm' = sum(`nyears') gen `pmx' = sum(`nyears') replace `pm' = `pm'/2 if _n==1 replace `pm' = (`pm'+`pmx'[_n-1])/2 if _n>=2 & _n<_N replace `pm' = `pm'-`nyears' if _n==_N tempvar linf qui gen `linf' = 0 if _n==1 qui replace `linf' = `linf'[_n-1]+`nyears'[_n-1] if _n>=2 replace `pmx' = `linf'[_n+1] replace `pmx' = `pmx'[_N-1]+((`pmx'[_N-1]-`pmx'[_N-2])) if _n==_N local lastyr = `linf'[_N] * noi di `lastyr' } * Geração de variáveis para YLL if "`noYLL'"=="" & "`noYLLx'"=="" { local v 1 while `v'<=`numvars' { tempvar PYLL`v' PEYLL`v' SEYLL`v' PYLL2`v' qui gen `PYLL`v''=. qui gen `PYLL2`v''=. qui gen `PEYLL`v''=. qui gen `SEYLL`v''=. local v = `v' + 1 } * Geração de PYLL (corrected for time lived in interval by those who died) if `pyll'>`lastyr' { local pyll = `lastyr' } local v 1 while `v'<=`numvars' { local y 0 local s 1 while `y'<`pyll' { local nry = `nyears' in `s' local dths = `_Dx`v''[`s'] local upplim = `linf'[`s']+`nyears'[`s'] if `upplim'>`pyll' { local diff = `pyll'-`linf'[`s'] local pmXX = `linf'[`s']+(((`linf'[`s']+`diff')-`linf'[`s'])/2) local dths = (`dths'/`nry')* `diff' qui replace `PYLL`v''= `dths'*(`pyll'-`pmXX') in `s' local guess = "yes" local y = `y' + `nry' } if `upplim'<=`pyll' { if `nry'==1 & "`yearmsg'"=="" { qui replace `PYLL`v''= `dths'*(`pyll'-`y') in `s' local y = `y' + 1 } else { local pmXX = `pm'[`s'] qui replace `PYLL`v''= `dths'*(`pyll'-`pmXX') in `s' local y = `y' + `nry' } } local s = `s' + 1 } local v = `v' + 1 } * Geração de PYLL2 (uncorrected = C Murray) if `pyll'>`lastyr' { local pyll = `lastyr' } local v 1 while `v'<=`numvars' { local y 0 local s 1 while `y'<`pyll' { local nry = `nyears' in `s' local dths = `_Dx`v''[`s'] local upplim = `linf'[`s']+`nyears'[`s'] if `upplim'>`pyll' { local diff = `pyll'-`linf'[`s'] local dths = (`dths'/`nry')* `diff' qui replace `PYLL2`v''= `dths'*(`pyll'-`linf') in `s' local guess = "yes" local y = `y' + `nry' } if `upplim'<=`pyll' { qui replace `PYLL2`v''= `dths'*(`pyll'-`linf') in `s' local y = `y' + `nry' } local s = `s' + 1 } local v = `v' + 1 } * Geração de PEYLL local v 1 while `v'<=`numvars' { local s 1 while `s'<=`max' { local expyli = _ExpYL in `s' local dths = `_Dx`v''[`s'] qui replace `PEYLL`v''= `dths'*(`expyli') in `s' local s = `s' + 1 } local v = `v' + 1 } * Geração de SEYLL (C Murray) stdexp local v 1 while `v'<=`numvars' { local s 1 while `s'<=`max' { local dths = `_Dx`v''[`s'] local first = `linf' in `s' qui replace `SEYLL`v''= `dths'*${E`first'} in `s' local s = `s' + 1 } local v = `v' + 1 } * Geração de spop(pyll) popt tempvar spop popt qui gen `popt' = sum(`P') qui sum `popt' , meanonly local popt = r(max) qui cap drop `popt' qui gen `spop' =. local y 0 local s 1 while `y'<`pyll' { local nry = `nyears' in `s' local pop = `P'[`s'] local upplim = `linf'[`s']+`nyears'[`s'] if `upplim'>`pyll' { local diff = `pyll'-`linf'[`s'] local pop = `pop' in `s' local pop = (`pop'/`nry')*`diff' qui replace `spop'= `pop' in `s' local y = `y' + `nry' } if `upplim'<=`pyll' { qui replace `spop'= `pop' in `s' local y = `y' + `nry' } local s = `s' + 1 } qui replace `spop' = sum(`spop') qui sum `spop' , meanonly local spop = r(max) qui cap drop `spop' * Geração de SOMAS local v 1 while `v'<=`numvars' { qui replace `PYLL`v''= sum(`PYLL`v'') qui su `PYLL`v'' , meanonly local pyll`v' = round(r(max),1) local rpy1`v' = (`pyll`v''/`spop')*1000 qui replace `PYLL2`v''= sum(`PYLL2`v'') qui su `PYLL2`v'' , meanonly local pyll2`v' = round(r(max),1) local rpy2`v' = (`pyll2`v''/`spop')*1000 qui replace `PEYLL`v''= sum(`PEYLL`v'') qui su `PEYLL`v'' , meanonly local peyll`v' = round(r(max),1) local rpey`v' = (`peyll`v''/`pop')*1000 qui replace `SEYLL`v''= sum(`SEYLL`v'') qui su `SEYLL`v'' , meanonly local seyll`v' = round(r(max),1) local rsey`v' = (`seyll`v''/`pop')*1000 * l agelab `_Dx`v'' _ExpYL `PYLL`v'' `PEYLL`v'' `SEYLL`v'' local v = `v' + 1 } } /* end of if noYLL=="" */ * -------------------- if "`noo'"=="" { if "`noYLL'"=="" & "`noYLLx'"=="" { di in gr " " di in gr " Years of Life Lost (YLL) due to specific causes of death" di in gr " --------------------------------------------------------" if "$by"~="" { di in gr " Results for group: `by' = " in ye `lab' } di in gr " " if "`allsct'"~="" { di in gr " * PYLL(`pyll')" _col(15) ": Potential Years of Life Lost until age `pyll'" di in gr " * PYLL(`pyll')u" _col(15) ": PYLL(`pyll') uncorrected for time lived in x-x+n by those who die" di in gr " * PEYLL " _col(15) ": Period Expected Years of Life Lost" di in gr " * SEYLL " _col(15) ": Standard Expected Years of Life Lost" di in gr " " } di in gr " C. of death | PYLL(" in ye `pyll' in gr ")" /* */ _col(36) "PYLL(" in ye `pyll' in gr ")u" _col(52) "PEYLL" _col(65) "SEYLL" di in gr _dup(15) "-" "+" _dup(54) "-" local v 1 while `v'<=`numvars' { local len = length("`var`v''") local len = 11-`len' di in ye " " _dup(`len') " " "`var`v''" in gr " | " in ye %12.0f `pyll`v'' _col(32) /* */ in ye %12.0f `pyll2`v'' _col(45) in ye %12.0f `peyll`v'' /* */ _col(58) in ye %12.0f `seyll`v'' * _col(78) in ye %3.1f `seyl2`v''/`seyll`v'' local v = `v' + 1 } di in gr _dup(15) "-" "+" _dup(54) "-" di in gr " " di in gr " " di in gr " Rates of Years of Life Lost" di in gr " ---------------------------" di in gr " " di in gr " C. of death | PYLL(" in ye `pyll' in gr ")" /* */ _col(36) "PYLL(" in ye `pyll' in gr ")u" _col(52) "PEYLL" _col(65) "SEYLL" di in gr _dup(15) "-" "+" _dup(54) "-" local v 1 while `v'<=`numvars' { local len = length("`var`v''") local len = 11-`len' di in ye " " _dup(`len') " " "`var`v''" in gr " | " in ye %12.4f `rpy1`v'' _col(32) /* */ in ye %12.4f `rpy2`v'' _col(45) in ye %12.4f `rpey`v'' /* */ _col(58) in ye %12.4f `rsey`v'' local v = `v' + 1 } di in gr _dup(15) "-" "+" _dup(54) "-" di in gr " * per 10^3 persons under `pyll' years: PYLL(`pyll') and PYLL(`pyll')u" di in gr " * per 10^3 population members: PEYLL and SEYLL" di in gr " " } if "`noYLLx'"~="" & "`noYLL'"=="" { di in gr " " di in gr " * Estimates for Years of Life Lost (YLL) cannot be produced because" di in gr " neither population structure -- pop( ) --, nor real number of" di in gr " deaths for each strata -- deaths( ) --, were declared." di in gr " " di in gr " * Without knowing whithin strata number of deaths, or information" di in gr " allowing their calculation, p.ex., pop( ), it is not possible" di in gr " to estimate YLL." di in gr " " } * --------- di in gr " " di in gr " Lifetime (at birth) prob. of death" di in gr " ----------------------------------" di in gr " " di in gr " C. of death | Prob." di in gr _dup(15) "-" "+" _dup(15) "-" local v 1 while `v'<=`numvars' { local len = length("`var`v''") local len = 11-`len' di in ye " " _dup(`len') " " "`var`v''" in gr " | " in ye %12.5f `lpd`v'' local v = `v' + 1 } di in gr _dup(15) "-" "+" _dup(15) "-" di in gr " " * --------- if "`not'"=="" { di in gr " " di in gr " Multiple Causes Life Table(s)" di in gr " -----------------------------" if "$by"~="" { di in gr " Results for group: `by' = " in ye `lab' } di in gr " " local w 1 while `w'<=`numvars' { if `w'<=5 { local q 1 } if `w'>5 & `w'<=10 { local q 2 } if `w'>10 & `w'<=15 { local q 3 } if `w'>15 & `w'<=20 { local q 4 } local spc = 8-length("`var`w''") local lstv`q' = "`lstv`q'' " + "`spc' " + "`var`w''" local lstD`q' = "`lstD`q'' " + "`_Dx`w''" local lstd`q' = "`lstd`q'' " + "`_dx`w''" local lstq`q' = "`lstq`q'' " + "`_qx`w''" local lstW`q' = "`lstW`q'' " + "`Wx`w''" local lstF`q' = "`lstF`q'' " + "`Fx`w''" local lstsW`q' = "`lstsW`q'' " + "`sW`w''" local lstsF`q' = "`lstsF`q'' " + "`sF`w''" local w = `w' + 1 } local f 1 if "`allsct'"=="" { local f = 2 } while `f'<=7 { if "`allsct'"=="" & `f'>2 & `f'<6 { local f = 5 } if `f'==1 { local StrL = "Strata" local StrS = "Strata" local StrSpc = 0 local gst = "Px" local st = "Dx" local gstl = "Population" local gvar = "`P'" local var = "_Dx" local fmt1 = "%12.0f" local fmt2 = "%10.0f" } if `f'==2 { local StrL = "Strata" local StrS = "Strata" local StrSpc = 0 local gst = "qx" local st = "qx" local gstl = "Total Risk" local gvar = "_qx" local var = "_qx" local fmt1 = "%12.5f" local fmt2 = "%10.5f" } if `f'==3 { local StrL = "Strata" local StrS = "Strata" local StrSpc = 0 local gst = "lx" local st = "dx" local gstl = ".Nr. Alive" local gvar = "_lx" local var = "_dx" local fmt1 = "%12.0f" local fmt2 = "%10.0f" } if `f'==4 { local StrL = " Age" local StrS = "Age" local StrSpc = 2 local gst = "Wx" local st = "Wx" local gstl = "Dths aft x" local gvar = "`sW'" local var = "Wx" local fmt1 = "%12.0f" local fmt2 = "%10.0f" } if `f'==5 { local StrL = " Age" local StrS = "Age" local StrSpc = 2 local gst = "Fx" local st = "Fx" local gstl = "Tot Pr Dth" local gvar = "`sF'" local var = "Fx" local fmt1 = "%12.5f" local fmt2 = "%10.5f" } if `f'==6 { local StrL = " Age" local StrS = "Age" local StrSpc = 2 local gst = "Wx" local st = "Px" local gstl = "Dths aft x" local gvar = "`sW'" local var = "sW" local fmt1 = "%12.0f" local fmt2 = "%10.5f" } if `f'==7 { local StrL = "`_dup(2) " "'" + "Age" local StrS = "Age" local StrSpc = 2 local gst = "Sx" local st = "Sx" local gstl = "All causes" local gvar = "_Surv" local var = "sF" local fmt1 = "%12.5f" local fmt2 = "%10.5f" } local w 1 while `w'<=4 { local lstv = "`lstv`w''" if "`lstv'"~="" { if `w'==1 { if `f'==1 { di in gr " Number of deaths (total and by cause)" } if `f'==2 { di in gr " Global and cause-specific probabilities of death in interval" } if `f'==3 { di in gr " Nr alive at age x and life table expected deaths by cause" } if `f'==4 { di in gr " Life table expected number of deaths after age x (total and by cause)" } if `f'==5 { di in gr " Cumulative distributions of deaths (total and by cause)" } if `f'==6 { di in gr " Lifetime, and beyond age x, cond. prob. of death: Pr(Dth by cause|x)" } if `f'==7 { di in gr " Probability of death after age x given death by cause (all & sp causes)" } local z1 = 1 local z2 = 2 local z3 = 3 local z4 = 4 local z5 = 5 } else { if `f'==1 { di in gr " Number of deaths (total and by cause) [cont.]" } if `f'==2 { di in gr " Global and cause-specific probabilities of death in interval [cont.]" } if `f'==3 { di in gr " Nr alive at age x and life table expected deaths by cause [cont.]" } if `f'==4 { di in gr " Life table expected number of deaths after age x (total and by cause) [cont.]" } if `f'==5 { di in gr " Cumulative distributions of deaths (total and by cause) [cont.]" } if `f'==6 { di in gr " Lifetime, and beyond age x, cond. prob. of death: Pr(Dth by cause|x) [cont.]" } if `f'==7 { di in gr " Probability of death after x given death by cause (all & sp causes) [cont.]" } if `w'==2 { local z1 = 6 local z2 = 7 local z3 = 8 local z4 = 9 local z5 = 10 } if `w'==3 { local z1 = 11 local z2 = 12 local z3 = 13 local z4 = 14 local z5 = 15 } if `w'==4 { local z1 = 16 local z2 = 17 local z3 = 18 local z4 = 19 local z5 = 20 } } tokenize "`lstv`w''" , parse(" ") local nargs : word count `lstv`w'' local nspaces = 26+(11*(`nargs')/2) di in gr _dup(`nspaces') "-" if `nargs'==10 { di in gr _col(22) "`gst' " /* */ _col(33) "`st'`z1'" /* */ _col(44) "`st'`z2'" /* */ _col(55) "`st'`z3'" /* */ _col(66) "`st'`z4'" /* */ _col(77) "`st'`z5'" di in gr _dup(`nspaces') "-" di in gr _col(3) _dup(`StrSpc') " " "`StrL'" _col(10) "| `gstl' " /* */ _col(28) _dup(`1') " " "`2'" /* */ _col(39) _dup(`3') " " "`4'" /* */ _col(50) _dup(`5') " " "`6'" /* */ _col(61) _dup(`7') " " "`8'" /* */ _col(72) _dup(`9') " " "`10'" } if `nargs'==8 { di in gr _col(22) "`gst' " /* */ _col(33) "`st'`z1'" /* */ _col(44) "`st'`z2'" /* */ _col(55) "`st'`z3'" /* */ _col(66) "`st'`z4'" di in gr _dup(`nspaces') "-" di in gr _col(3) _dup(`StrSpc') " " "`StrL'" _col(10) "| `gstl' " /* */ _col(28) _dup(`1') " " "`2'" /* */ _col(39) _dup(`3') " " "`4'" /* */ _col(50) _dup(`5') " " "`6'" /* */ _col(61) _dup(`7') " " "`8'" } if `nargs'==6 { di in gr _col(22) "`gst' " /* */ _col(33) "`st'`z1'" /* */ _col(44) "`st'`z2'" /* */ _col(55) "`st'`z3'" di in gr _dup(`nspaces') "-" di in gr _col(3) _dup(`StrSpc') " " "`StrL'" _col(10) "| `gstl' " /* */ _col(28) _dup(`1') " " "`2'" /* */ _col(39) _dup(`3') " " "`4'" /* */ _col(50) _dup(`5') " " "`6'" } if `nargs'==4 { di in gr _col(22) "`gst' " /* */ _col(33) "`st'`z1'" /* */ _col(44) "`st'`z2'" di in gr _dup(`nspaces') "-" di in gr _col(3) _dup(`StrSpc') " " "`StrL'" _col(10) "| `gstl' " /* */ _col(28) _dup(`1') " " "`2'" /* */ _col(39) _dup(`3') " " "`4'" } if `nargs'==2 { di in gr _col(22) "`gst' " /* */ _col(33) "`st'`z1'" di in gr _dup(`nspaces') "-" di in gr _col(3) _dup(`StrSpc') " " "`StrL'" _col(10) "| `gstl' " /* */ _col(28) _dup(`1') " " "`2'" } di in gr _dup(`nspaces') "-" local s 1 while `s'<=$max { if "`StrS'"=="Strata" { if "`label'"=="" { local str = `xx' in `s' local len = 6-length("`str'") } if "`label'"~="" { local str = `Labv' in `s' local len = 8-length("`str'") } } if "`StrS'"=="Age" { local str = `linf' in `s' local len = 6-length("`str'") } local Px = `gvar' in `s' local na = `z1'+(`nargs'/2)-1 local r = `z1' while `r'<=`na' { local Dx`r' = ``var'`r'' in `s' local r = `r' + 1 } if `nargs'==10 { di in ye _dup(`len') " " "`str'" in gr _col(10) "| " /* */ in ye `fmt1' `Px' /* */ " " `fmt2' `Dx`z1'' " " `fmt2' `Dx`z2'' /* */ " " `fmt2' `Dx`z3'' " " `fmt2' `Dx`z4'' /* */ " " `fmt2' `Dx`z5'' } if `nargs'==8 { di in ye _dup(`len') " " "`str'" in gr _col(10) "| " /* */ in ye `fmt1' `Px' /* */ " " `fmt2' `Dx`z1'' " " `fmt2' `Dx`z2'' /* */ " " `fmt2' `Dx`z3'' " " `fmt2' `Dx`z4'' } if `nargs'==6 { di in ye _dup(`len') " " "`str'" in gr _col(10) "| " /* */ in ye `fmt1' `Px' /* */ " " `fmt2' `Dx`z1'' " " `fmt2' `Dx`z2'' /* */ " " `fmt2' `Dx`z3'' } if `nargs'==4 { di in ye _dup(`len') " " "`str'" in gr _col(10) "| " /* */ in ye `fmt1' `Px' /* */ " " `fmt2' `Dx`z1'' " " `fmt2' `Dx`z2'' } if `nargs'==2 { di in ye _dup(`len') " " "`str'" in gr _col(10) "| " /* */ in ye `fmt1' `Px' /* */ " " `fmt2' `Dx`z1'' } local s = `s' + 1 } di in gr _dup(`nspaces') "-" di in gr _dup(`nspaces') " " di in gr _dup(`nspaces') " " } local c = `w' + 1 local lstv = "`lstv`c''" local w = `w' + 1 } local f = `f' + 1 } } /* end of if not */ } /* end of if noo */ if "`gsc'"~="" { quietly { tempvar pm pmx gen `pm' = sum(`nyears') gen `pmx' = sum(`nyears') replace `pm' = `pm'/2 if _n==1 replace `pm' = (`pm'+`pmx'[_n-1])/2 if _n>=2 & _n<_N replace `pm' = `pm'-`nyears' if _n==_N tempvar linf qui gen `linf' = 0 if _n==1 qui replace `linf' = `linf'[_n-1]+`nyears'[_n-1] if _n>=2 replace `pmx' = `linf'[_n+1] replace `pmx' = `pmx'[_N-1]+((`pmx'[_N-1]-`pmx'[_N-2])) if _n==_N } local maxx = `pm'[_N] local uppx = ((int(`maxx'/10))*11) * l `pm' `pmx' `linf' `_qx1' if `_qx1'~=. local k 1 while `k'<=`numvars' { qui format `_qx`k'' %5.4f qui su `_qx`k'' , meanonly local maxy = r(max) local step = `maxy'/10 local maxy = (`step'*10)+(`step'/2) set more 0 more set more 1 if "`by'"~="" { local t1 = "t1(Subgroup: `by'=`lab')" } gr `_qx`k'' `pm' , c(l) s(o) sort `options' xlab(0(5)`uppx') /* */ ylab(0(`step')`maxy') `t1' /* */ gap(8) b2(Age level) l1(q(x)i) /* */ b1(Risk of death due to cause `var`k'' [q(x)i]) set more 0 more set more 1 local k = `k' + 1 } local k 1 while `k'<=`numvars' { qui format `Fx`k'' %5.3f label var `Fx`k'' "`var`k''" local flist = "`flist' " + "`Fx`k''" local cc = "`cc'" + "l" local s = substr("odp.odp.odp.odp.odp.",`k',1) local ss = "`ss'" + "`s'" local k = `k' + 1 } if "`by'"=="" { keyplot `flist' `linf' , c(`cc') s(`ss') sort `options' xlab(0(5)`uppx') /* */ ylab(0(.1)1) /* */ gap(6) b2(Age level) l1(F(x)i) varlbl /* */ b1(Cumulative distributions of age at death [F(x)i]) } if "`by'"~="" { keyplot `flist' `linf' , c(`cc') s(`ss') sort `options' xlab(0(5)`uppx') /* */ ylab(0(.1)1) varlbl /* */ gap(6) b2(Age level [Subgroup: `by'=`lab']) l1(F(x)i) /* */ b1(Cumulative distributions of age at death [F(x)i]) } set more 0 more set more 1 local v 1 while `v'<=`numvars' { qui su `sW`v'' , meanonly local maxy = r(max) local step = `maxy'/10 local maxy = (`step'*11)+(`step'/2) qui format `sW`v'' %5.3f label var `sW`v'' "`var`v''" local vlabel : variable label `sW`v'' if "`by'"=="" { gr `sW`v'' `linf' , c(l) s(o) sort `options' xlab(0(5)`uppx') /* */ ylab(0(`step')`maxy') /* */ t1(Lifetime (at birth and rest of life) probability of death by `vlabel') /* */ t2(P(x)i = P(dth by cause | dth after x)) /* */ gap(6) b2(Age level) l1(P(x)i) /* */ b1(Probability of death by cause given death after age x) } if "`by'"~="" { gr `sW`v'' `linf' , c(l) s(o) sort `options' xlab(0(5)`uppx') /* */ ylab(0(`step')`maxy') /* */ t1(Lifetime (at birth and rest of life) probability of death by `vlabel') /* */ t2(P(x)i = P(death by `vlabel' | death after x)) /* */ gap(6) b2(Age level [Subgroup: `by'=`lab']) l1(P(x)i) /* */ b1(Probability of death by cause given death after age x) } set more 0 more set more 1 local v = `v' + 1 } set more 0 more set more 1 local k 1 while `k'<=`numvars' { qui format `sF`k'' %5.3f label var `sF`k'' "`var`k''" local cc = "`cc'" + "l" local s = substr("odp.odp.odp.odp.odp.",`k',1) local ss = "`ss'" + "`s'" local k = `k' + 1 } if "`by'"=="" { keyplot `sFlst' `linf' , c(`cc') s(`ss') sort `options' xlab(0(5)`uppx') /* */ ylab(0(.1)1) varlbl /* */ gap(6) b2(Age level -- S(x)i = Pr(dth after x | dth by cause)) l1(S(x)i) /* */ b1(Survival probability conditional on cause of death) } if "`by'"~="" { keyplot `sFlst' `linf' , c(`cc') s(`ss') sort `options' xlab(0(5)`uppx') /* */ ylab(0(.1)1) varlbl gap(6) /* */ b2(Age level -- S(x)i = Pr(dth after x | dth by cause) [Subgroup: `by'=`lab']) l1(S(x)i) /* */ b1(Survival probability conditional on cause of death) } set more 0 more set more 1 } /* end of if grsc~="" */ if ("`keep'"~="" & "`fake'"=="") | "`saving'"~="" { local v 1 while `v'<=`numvars' { qui replace _qx`v' = `_qx`v'' local lbl = "Pr(dying|x) for `var`v''" label var _qx`v' "`lbl'" qui replace _Wx`v' = `Wx`v'' local lbl = "E(deaths) after x for `var`v''" label var _Wx`v' "`lbl'" qui replace _Fx`v' = `Fx`v'' local lbl = "Cum Distr of deaths for `var`v''" label var _Fx`v' "`lbl'" local v = `v' + 1 } } end program define stdexp version 6.0 * Coale & Demeny (1989) West Level 26 Standard Expectation of Life values. * Original data, as taken from C. Murray & A. Lopez, "The global burden of * disease", p. 17, had values for ages 0,1,5,10,15,20,...95,100. * The values for other ages were estimated by average interpolation by Carlos * Ramalheira (Aug 2000) global E0 = "82.50" global E1 = "81.84" global E2 = "80.87" global E3 = "79.90" global E4 = "78.92" global E5 = "77.95" global E6 = "76.96" global E7 = "75.97" global E8 = "74.97" global E9 = "73.98" global E10 = "72.99" global E11 = "72.00" global E12 = "71.00" global E13 = "70.01" global E14 = "69.01" global E15 = "68.02" global E16 = "67.03" global E17 = "66.04" global E18 = "65.06" global E19 = "64.07" global E20 = "63.08" global E21 = "62.10" global E22 = "61.12" global E23 = "60.13" global E24 = "59.15" global E25 = "58.17" global E26 = "57.19" global E27 = "56.21" global E28 = "55.23" global E29 = "54.25" global E30 = "53.27" global E31 = "52.29" global E32 = "51.31" global E33 = "50.34" global E34 = "49.36" global E35 = "48.38" global E36 = "47.41" global E37 = "46.44" global E38 = "45.47" global E39 = "44.50" global E40 = "43.53" global E41 = "42.57" global E42 = "41.61" global E43 = "40.64" global E44 = "39.68" global E45 = "38.72" global E46 = "37.77" global E47 = "36.83" global E48 = "35.88" global E49 = "34.94" global E50 = "33.99" global E51 = "33.07" global E52 = "32.14" global E53 = "31.22" global E54 = "30.29" global E55 = "29.37" global E56 = "28.46" global E57 = "27.55" global E58 = "26.65" global E59 = "25.74" global E60 = "24.83" global E61 = "23.95" global E62 = "23.07" global E63 = "22.20" global E64 = "21.32" global E65 = "20.44" global E66 = "19.59" global E67 = "18.74" global E68 = "17.90" global E69 = "17.05" global E70 = "16.20" global E71 = "15.42" global E72 = "14.63" global E73 = "13.85" global E74 = "13.06" global E75 = "12.28" global E76 = "11.60" global E77 = "10.93" global E78 = "10.25" global E79 = "9.58" global E80 = "8.90" global E81 = "8.36" global E82 = "7.83" global E83 = "7.29" global E84 = "6.76" global E85 = "6.22" global E86 = "5.83" global E87 = "5.43" global E88 = "5.04" global E89 = "4.64" global E90 = "4.25" global E91 = "3.98" global E92 = "3.71" global E93 = "3.43" global E94 = "3.16" global E95 = "2.89" global E96 = "2.71" global E97 = "2.53" global E98 = "2.36" global E99 = "2.18" global E100 = "2.00" end /* collapsed years 93-98 lifetabl , s(gretar) p( pop) d( obtot) by(sexo) ny(years) sc(AllOthr INF MENTAIS TUM SNC CIRC TRAUMA) egen AllOthr=rsum( END HEM RESP DIG GENUR DERM OSTEO CONG PER IND GRAV) lifetabl if ano==1993 , s(gretar) p( pop) d( obtot) by(sexo) ny(years) sc(AllOthr INF TUM MENTAIS SNC CIRC TRAUMA) lifetabl if sex<3 , s(strata) r( Rx100000) by(sex) sc( Rx100 Rx10 Rx1) not allr lifetabl , s(strata) d( deaths) p(pop) not ny(years) sc( lungcan ihd motor allother) gsc lifetabl if sex<3 , s(strata) r(Rx100000) by(sex) grphs not lifetabl , s(strata) r(Rxdiff) by(dgroup) ny(years) grphs not lifetabl , s(strata) d(diff) p(pop) by(dgroup) ny(years) gd not lifetabl if dg==4 | dg==3 , s(strata) d(diff) p(pop) by(dgroup) ny(years) gd not */