That code does not look like it will do what you ask. It will leave you with all the pidp's whose first wave in the survey data is 5 or earlier.
I don't understand your data and variables well enough to advise you on how to do it. You mentioned in an earlier post that there is a variable that identifies those who died during the follow-up period. Is there also a variable that tells you when they died?
Also I'm not sure what you even mean by "survived" in this context? Do you mean survived in the biologic sense of still being alive?
Or do you mean survived and still participated. In that case, you can judge it by whether or not the person has any wave 5 or later available, which would be:
But, I want to emphasize that I'm not sure this code does what you want, because I'm not sure what you mean by survived, and I'm not sure what the wave variable actually does, since it can have missing values.
I don't understand your data and variables well enough to advise you on how to do it. You mentioned in an earlier post that there is a variable that identifies those who died during the follow-up period. Is there also a variable that tells you when they died?
Also I'm not sure what you even mean by "survived" in this context? Do you mean survived in the biologic sense of still being alive?
Or do you mean survived and still participated. In that case, you can judge it by whether or not the person has any wave 5 or later available, which would be:
Code:
by pidp, sort: egen survived_to_5 = max(wave >= 5 & !missing(wave))
Comment