Each person in the dataset has an index date that is independent of chronic conditions. Each person is enrolled from 1-year prior to their index date up to 10-years after their index date. I am tracking evidence of chronic conditions and placing the disease indicator variables (0/1 for no/yes) in quarters based on the date of evidence of that chronic condition (using claims data). So, each person has 4 baseline quarters and up to 40 quarters, but this study will allow for drop out, so the post-index eligible quarters will range from 1-40. Everyone has at least 1 year baseline, so everyone has the 4 quarters prior to the index date. Once the chronic condition is flagged, I would like to carry forward the "1", from whatever quarter that chronic condition was first identified, through the end of each person's follow-up quarters. E.g., condition was identified in quarter 2, then flag that condition as being present through the end of their follow-up, for example, quarter 17. To do this, I think I first need to expand the quarterly indicator variable consecutively, which is NOT a date variable; it is an integer/numeric variable (e.g., -4 is the 4th quarter prior to the index date, 1 is the first quarter after the index date, up to 40 quarters). Currently, I only have quarters where there was a hospital encounter and thus a claim (1) or no claim (0) for each chronic condition. I think, second, I need to carry forward the "1" (indicating yes to evidence of that condition) from the initial quarter to all remaining quarters, contingent on each person's enrollment. Below is an example dataset that I have, followed but what I would like. For simplicity, I am including 1 condition. I figured I will have to do this separately for each condition then merge the files. HAVE ID Last_enrollment_quarter Quarter_evidence_of_condition Chronic_condition 1 3 -3 0 1 3 -2 1 1 3 1 0 2 40 -4 0 2 40 -2 0 2 40 -1 1 2 40 1 1 2 40 4 1 2 40 17 0 2 40 25 0 3 24 12 0 3 24 13 0 3 24 15 0 3 24 16 0 3 24 22 0 4 2 -2 1 5 12 -1 1 5 12 1 0 5 12 4 0 WANT ID Last_enrollment_quarter Quarter_evidence_of_condition Chronic_condition 1 3 -4 0 1 3 -3 0 1 3 -2 1 1 3 -1 1 1 3 1 1 1 3 2 1 1 3 3 1 2 40 -4 0 2 40 -3 0 2 40 -2 0 2 40 -1 1 2 40 1 1 2 40 2 1 2 40 3 1 2 40 4 1 2 40 5 1 2 40 6 1 2 40 7 1 2 40 8 1 2 … and so on to… … and so on to… 1 2 40 40 1 3 24 -4 0 3 24 -3 0 3 24 -2 0 3 24 -1 0 3 24 1 0 3 24 2 0 3 24 3 0 3 24 4 0 3 24 5 0 3 … and so on to… … and so on to… 0 3 24 24 0 4 2 -4 0 4 2 -3 0 4 2 -2 1 4 2 -1 1 4 2 1 1 4 2 2 1 … … …
... View more