I have a longitudinal data formatting like below. I want to create an index for each subject regarding their 'disease' status. If disease status is NA or 0, the index would be 0; if disease status is 1, the index would be 1.
However, I want each row within the same subject to have the same index, disregard at what observational point their status is. Say, as long as the individual has 'disease=1' disregard which row, the index should be 1 for all rows for that individual.
Anybody has good ideas? Thank!
id disease index 1 NA 0 1 NA 0 1 NA 0 2 NA 1 2 1 1 2 1 1 3 NA 1 3 NA 1 3 1 1 4 1 1 4 0 1 4 0 1 5 0 0 5 0 0 5 0 0