Hi Everyone,
I have a data management problem that I am struggling with. I have a longitudinal dataset with 10 timepoints in which a person can go on and off a medication. I would like to create a new variable that indicates medication phase - i.e. takes one value for "before medication," another value for "first medication," another value for "after first medication", another value for "second medication" and a final value for "after second medication." So the data are set up as below, and I want a new variable called drug status, that for this example, would be 1,1,2,2,3,4,5,5,5,5. Any ideas would be greatly appreciated! Thanks!
Andrea
I have a data management problem that I am struggling with. I have a longitudinal dataset with 10 timepoints in which a person can go on and off a medication. I would like to create a new variable that indicates medication phase - i.e. takes one value for "before medication," another value for "first medication," another value for "after first medication", another value for "second medication" and a final value for "after second medication." So the data are set up as below, and I want a new variable called drug status, that for this example, would be 1,1,2,2,3,4,5,5,5,5. Any ideas would be greatly appreciated! Thanks!
id | time | drug |
1 | 1 | 0 |
1 | 2 | 0 |
1 | 3 | 1 |
1 | 4 | 1 |
1 | 5 | 0 |
1 | 6 | 1 |
1 | 7 | 0 |
1 | 8 | 0 |
1 | 9 | 0 |
1 | 10 | 0 |
Comment