Hi,
I am working with cohort life tables and generating the values of lx (number of people alive) at age x, dx (number of deaths) at age x based on qx (probability of death before next birthday). I am using dyngen to dynamically update values and would like help/advice to speed it up.
Three variables: q, l, and d for 90 observations (rows).
Initial values are as follows:
q0 to q90 are external inputs.
l0 or the starting value of lx is external input.
d0 = l0*q0
Subsequent rows l1 and d1 are calculated as:
l1=l0-d0
d1=l1*q1
The process continues row by row until l90.
I use the following Stata code (dyngen) in Stata MP 17:
My question is, is there a way to speed up this line by line calculation? I use this in a simulation and the dyngen is the only bottle-neck.
Thank you
Parth
I am working with cohort life tables and generating the values of lx (number of people alive) at age x, dx (number of deaths) at age x based on qx (probability of death before next birthday). I am using dyngen to dynamically update values and would like help/advice to speed it up.
Three variables: q, l, and d for 90 observations (rows).
Initial values are as follows:
q0 to q90 are external inputs.
l0 or the starting value of lx is external input.
d0 = l0*q0
Subsequent rows l1 and d1 are calculated as:
l1=l0-d0
d1=l1*q1
The process continues row by row until l90.
I use the following Stata code (dyngen) in Stata MP 17:
Code:
dyngen {
update lx = lx[_n-1] - dx[_n-1] , missval(`intial_lx')
update dx = lx[_n] * qx[_n] , missval(`intial_dx')
}
Thank you
Parth

Comment