I am trying to reshape a dataset from long to wide. Initially I was getting the error that the variable I had indicated for "j" was not unique within the id (study_id). Therefore I created a new variable especially for this purpose that would be unique within STUDY_ID using the following:
Despite this I am now receiving the error message that newid is not unique within study_id. Any advice? A sample of my dataset (dummy data for confidentiality reasons) is be below.
Code:
egen newid = group(study_id)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str2 study_id str10 aerptdat str8 aerptime str26 aeterm str10 aestdat byte(aeout aesev) str10 aeendat byte aeser str2 aeinit int aespid str10 eventstartdateheader byte(eventrepeatkey newid) "AA" "09/01/2023" "18:17:48" "Headache" "24/12/2021" 5 2 "" 1 "HW" 378 "09/01/2023" 1 1 "AA" "09/01/2023" "18:17:48" "Headache" "" 1 2 "26/12/2021" 1 "HW" 378 "09/01/2023" 2 1 "AA" "09/01/2023" "18:17:48" "Diarrhoea" "25/12/2021" 5 2 "" 1 "HW" 379 "09/01/2023" 3 1 "AA" "09/01/2023" "18:17:48" "Diarrhoea" "" 1 2 "26/12/2021" 1 "HW" 379 "09/01/2023" 4 1 "AA" "09/01/2023" "18:17:48" "Generally feeling unwell" "25/12/2021" 5 2 "" 1 "HW" 377 "09/01/2023" 5 1 "AA" "09/01/2023" "18:17:48" "Generally feeling unwell" "" 1 2 "27/12/2021" 1 "HW" 377 "09/01/2023" 6 1 "AA" "09/01/2023" "18:17:48" "Abdominal pain" "25/12/2021" 5 2 "" 1 "HW" 380 "09/01/2023" 7 1 "AA" "09/01/2023" "18:17:48" "Abdominal pain" "" 1 2 "26/12/2021" 1 "HW" 380 "09/01/2023" 8 1 "AA" "09/01/2023" "18:17:48" "Abdominal pain" "29/12/2021" 5 2 "" 1 "HW" 380 "09/01/2023" 9 1 "AA" "09/01/2023" "18:17:48" "Abdominal pain" "" 1 2 "30/12/2021" 1 "HW" 380 "09/01/2023" 10 1 "BB" "09/01/2023" "18:17:48" "Headache" "15/03/2022" 5 3 "" 1 "HW" 387 "09/01/2023" 1 2 "BB" "09/01/2023" "18:17:48" "Headache" "" 1 3 "16/03/2022" 1 "HW" 387 "09/01/2023" 2 2 "BB" "09/01/2023" "18:17:48" "Headache" "17/03/2022" 5 3 "" 1 "HW" 387 "09/01/2023" 3 2 "BB" "09/01/2023" "18:17:48" "Loss of smell and or taste" "15/03/2022" 5 2 "" 1 "HW" 392 "09/01/2023" 4 2 "BB" "09/01/2023" "18:17:48" "Loss of smell and or taste" "" 1 2 "16/03/2022" 1 "HW" 392 "09/01/2023" 5 2 "CC" "09/01/2023" "18:17:48" "Headache" "16/11/2021" 5 2 "" 1 "HW" 403 "09/01/2023" 1 3 "CC" "09/01/2023" "18:17:48" "Headache" "" 1 2 "21/11/2021" 1 "HW" 403 "09/01/2023" 2 3 "CC" "09/01/2023" "18:17:48" "Headache" "22/11/2021" 5 2 "" 1 "HW" 403 "09/01/2023" 3 3 "CC" "09/01/2023" "18:17:48" "Fever" "16/11/2021" 5 3 "" 1 "HW" 399 "09/01/2023" 4 3 "CC" "09/01/2023" "18:17:48" "Fever" "" 1 3 "21/11/2021" 1 "HW" 399 "09/01/2023" 5 3 "CC" "09/01/2023" "18:17:48" "Fever" "22/11/2021" 5 3 "" 1 "HW" 399 "09/01/2023" 6 3 "CC" "09/01/2023" "18:17:48" "Loss of smell and or taste" "16/11/2021" 5 3 "" 1 "HW" 404 "09/01/2023" 7 3 "CC" "09/01/2023" "18:17:48" "Loss of smell and or taste" "" 1 3 "21/11/2021" 1 "HW" 404 "09/01/2023" 8 3 "CC" "09/01/2023" "18:17:48" "Loss of smell and or taste" "22/11/2021" 5 3 "" 1 "HW" 404 "09/01/2023" 9 3 end
Comment