Essentially, I have a row for every hospital visit for each patient (could be anywhere from 1-100 rows). At it's most basic, each row has variables for patient ID, all outcomes (var1, var2, var3,...,var25), and the date of the hospital visit (as days from enrollment).
The outcomes are all coded and are string variables.
Code:
ID | outcome1 | outcome2 | outcome3 | outcome4 | outcomeN | date | visit |
001 | X1 | X2 | X3 | 5 | 1 | ||
001 | X4 | X5 | 45 | 2 | |||
001 | X1 | X2 | X5 | X6 | X7 | 104 | 3 |
001 | X1 | 200 | 4 | ||||
001 | X6 | 302 | 5 | ||||
001 | X1 | X2 | 333 | 6 | |||
002 | X4 | 32 | 1 | ||||
002 | X7 | 100 | 2 | ||||
002 | X1 | X2 | 121 | 3 |
So using the first row of the example above:
Code:
Starts as:
ID | outcome1 | outcome2 | outcome3 | outcome4 | outcomeN | date | visit |
001 | X1 | X2 | X3 | 5 | 1 |
Convert to:
ID | outcome | date | visit |
001 | X1 | 5 | 1 |
001 | X2 | 5 | 1 |
001 | X3 | 5 | 1 |
Apologies, for the long post, I hope this makes sense.
0 Response to Convert multiple similar variables into one variable with multiple observations (rows)
Post a Comment