Dear Stata users,
For the example dataset below, I would like to move the examdatetime values for a specific patient when the event_type is 2, so that they appear in the same row as when their event_type is 1.
I would want my dataset to look like below
My dataset consists of 500,000 observations and 13 variables, so reshaping the dataset might not be feasible?, but I'm unsure of the best approach.
Any advice would be greatly appreciated!
Regards,
Fouziah
For the example dataset below, I would like to move the examdatetime values for a specific patient when the event_type is 2, so that they appear in the same row as when their event_type is 1.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str15 p_ID float event_type str22 examdatetime "100175" 1 "" "100175" 2 "30/03/2020 6:17:00 PM" "100175" 2 "30/03/2020 6:17:00 PM" "100175" 2 "30/03/2020 6:17:00 PM" "100175" 2 "30/03/2020 6:48:00 PM" "100175" 3 "" end
I would want my dataset to look like below
p_ID | event_type | examdatetime | examdatetime1 | examdatetime2 | examdatetime3 | examdatetime4 |
map_code_100175 1 | 1 | 31/03/2020 18:17 | 30/03/2020 18:17 | 30/03/2020 18:17 | 30/03/2020 18:48 | |
map_code_100175 2 | 2 | 31/03/2020 18:17 | ||||
map_code_100175 2 | 2 | 30/03/2020 18:17 | ||||
map_code_100175 2 | 2 | 30/03/2020 18:17 | ||||
map_code_100175 2 | 2 | 30/03/2020 18:48 | ||||
map_code_100175 3 | 3 |
My dataset consists of 500,000 observations and 13 variables, so reshaping the dataset might not be feasible?, but I'm unsure of the best approach.
Any advice would be greatly appreciated!
Regards,
Fouziah
Comment