Hi everyone,
I hope you're all well. I need to generate weights for longitudinal analysis. For that, I need to multiply the cross-sectional weight of a given individual the first year I observe them in my observation window, and multiply it by the inverse probability of that individual staying in the sample in every subsequent year, until the last year this individual is observed. To illustrate, see below (inspired by my real data but changed for anonymity purposes).

Take the example of the person with id==2. The variable I want to create is lw. For that, I need to multiply lworiginal (of value 12268.77 in this example) by every single value of the variable "hh_stayprob" from 2002 to 2018 (in this specific case, please ignore the discrepancy between 2009 and 2017; let us just imagine that it is all continuous from 2001 to the end of the observation window and that 2017 is 2010 and 2018 is 2011). In that specific case of course an option that works is:
gen lw=.
by pid: replace lw=lworiginal*hh_stayprob[_n+1]*hh_stayprob[_n+2]*hh_stayprob[_n+3]*hh_stayprob[_n+4]*hh_stayprob[_n+5]*hh_stayprob[_n+6]*hh_stayprob[_n+7]*hh_stayprob[_n+8]*hh_stayprob[_n+9]*hh_stayprob[_n+10]
The issue is, this would work for this specific case, but different individuals have different lengths of stays in my dataset. Some individuals stay only two or three years in the sample. Others stay longer, up to 30+ years. Therefore, this command is specifically applicable to the case of an individual observed for 11 years like in this example, but does not work in other cases. Essentially what I am after, and have been struggling with, is a generic command that would work in all cases such that, regardless of how long an individual is observed for, I can have:
by pid: lw=lworiginal*hh_stayprob[_n+1]*....*hh_stayprob[_n=_N]
Would anyone please be able to help? I thought I would be able to resolve that easily. I would be super grateful for any advice!
Thank you in advance,
Guillaume Paugam
I hope you're all well. I need to generate weights for longitudinal analysis. For that, I need to multiply the cross-sectional weight of a given individual the first year I observe them in my observation window, and multiply it by the inverse probability of that individual staying in the sample in every subsequent year, until the last year this individual is observed. To illustrate, see below (inspired by my real data but changed for anonymity purposes).
Take the example of the person with id==2. The variable I want to create is lw. For that, I need to multiply lworiginal (of value 12268.77 in this example) by every single value of the variable "hh_stayprob" from 2002 to 2018 (in this specific case, please ignore the discrepancy between 2009 and 2017; let us just imagine that it is all continuous from 2001 to the end of the observation window and that 2017 is 2010 and 2018 is 2011). In that specific case of course an option that works is:
gen lw=.
by pid: replace lw=lworiginal*hh_stayprob[_n+1]*hh_stayprob[_n+2]*hh_stayprob[_n+3]*hh_stayprob[_n+4]*hh_stayprob[_n+5]*hh_stayprob[_n+6]*hh_stayprob[_n+7]*hh_stayprob[_n+8]*hh_stayprob[_n+9]*hh_stayprob[_n+10]
The issue is, this would work for this specific case, but different individuals have different lengths of stays in my dataset. Some individuals stay only two or three years in the sample. Others stay longer, up to 30+ years. Therefore, this command is specifically applicable to the case of an individual observed for 11 years like in this example, but does not work in other cases. Essentially what I am after, and have been struggling with, is a generic command that would work in all cases such that, regardless of how long an individual is observed for, I can have:
by pid: lw=lworiginal*hh_stayprob[_n+1]*....*hh_stayprob[_n=_N]
Would anyone please be able to help? I thought I would be able to resolve that easily. I would be super grateful for any advice!
Thank you in advance,
Guillaume Paugam
Comment