Hello, I am very new to stata and trying to teach myself how to use it. I wanted to determine if there is a way to generate a new variable, or replace an existing variable for all rows relevant to a specific patient ID, based on an observation from a single row.
So if the observation for Study ID #1 in visit 5 is 1, how can I replace the value for newvar in all rows for patient #1 if var1==1 at visit 5.
Hopefully this makes sense.
Thank you so much.
ID | var1 | visit | newvar |
1 | 0 | 1 | 0 |
1 | 0 | 2 | 0 |
1 | 0 | 3 | 0 |
1 | 1 | 4 | 0 |
1 | 0 | 5 | 0 |
2 | 0 | 1 | 0 |
2 | 1 | 2 | 0 |
2 | 0 | 3 | 0 |
2 | 0 | 4 | 0 |
Hopefully this makes sense.
Thank you so much.
Comment