Hello everyone,
Thank you in advance for your guidance and advice. I am a new Stata user working with a large medical database. I have data where each patient has an "inc_key" as their unique identifier. This subset of data provides multiple observations for each inc_key to provide an injury score, description, and body region. I want to have in the end one observation with the injury score for each body region for that one specific inc_key (i.e. the variables would be inc_key, aisseverity of issregion __, aisseverity of issregion ___, etc. with the values of each "aisseverity ofissregion__" being the average aisseverity score for that body region). There are a total of 6 issregions.
My original, and naive, approach was to use "reshape wide aisseverity, i(inc_key) j(issregion)" but this failed, obviously, because inc_key was not providing unique results (i.e. one inc_key could have multiple observations with the same issregion due to varying aispredot values).
My idea now was to try and have Stata create a mean aisseverity value by issregion for each inc_key. However I am having trouble telling Stata to do just that. Also, I am worried I do not know how to have it store that mean in a specific new data frame.
I have attached below a subset of my data for reference.
Thank you in advance for your guidance and advice. I am a new Stata user working with a large medical database. I have data where each patient has an "inc_key" as their unique identifier. This subset of data provides multiple observations for each inc_key to provide an injury score, description, and body region. I want to have in the end one observation with the injury score for each body region for that one specific inc_key (i.e. the variables would be inc_key, aisseverity of issregion __, aisseverity of issregion ___, etc. with the values of each "aisseverity ofissregion__" being the average aisseverity score for that body region). There are a total of 6 issregions.
My original, and naive, approach was to use "reshape wide aisseverity, i(inc_key) j(issregion)" but this failed, obviously, because inc_key was not providing unique results (i.e. one inc_key could have multiple observations with the same issregion due to varying aispredot values).
My idea now was to try and have Stata create a mean aisseverity value by issregion for each inc_key. However I am having trouble telling Stata to do just that. Also, I am worried I do not know how to have it store that mean in a specific new data frame.
I have attached below a subset of my data for reference.
Code:* Example generated by -dataex-. For more info, type help dataex clear input double inc_key str8 aisversion long aispredot byte aisseverity strL aisdescription byte issregion 220066260699 "AIS 1998" 110202 1 "Scalp, Abrasion" 6 220069795312 "AIS 1998" 110202 1 "Scalp, Abrasion" 6 220072298312 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220069860051 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220072298525 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220064485938 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220067924505 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220072298488 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220064507567 "AIS 1998" 110402 1 "Scalp, Contusion (includes subgaleal hematoma)" 6 220064632104 "AIS 1998" 110600 1 "Scalp, Laceration, NFS" 6 220064611195 "AIS 1998" 110600 1 "Scalp, Laceration, NFS" 6 220068517163 "AIS 1998" 110600 1 "Scalp, Laceration, NFS" 6 220072298381 "AIS 1998" 110600 1 "Scalp, Laceration, NFS" 6 220066315040 "AIS 1998" 110602 1 "Scalp, Laceration, Minor" 6 220072298548 "AIS 1998" 110602 1 "Scalp, Laceration, Minor" 6 220072298350 "AIS 1998" 110604 2 "Scalp, Laceration, Major (> 10 cm long and subcateneous tissue)" 6 220064507353 "AIS 1998" 115099 9 "Closed Head Injury, NFS" 1 220069746308 "AIS 1998" 121002 5 "Internal Carotid Artery, Laceration" 1 220069716757 "AIS 1998" 122804 3 "Vertebral Artery, Thrombosis" 1 220068276145 "AIS 1998" 140202 5 "Brain Stem, Compression" 1 220068517100 "AIS 1998" 140418 4 "Cerebellum, Hematoma Epi/Extradural, Small" 1 220068517254 "AIS 1998" 140442 4 "Cerebellum, Hematoma, Subdural, Small" 1 220064632738 "AIS 1998" 140602 3 "Cerebrum, Contusion, NFS" 1 220068517100 "AIS 1998" 140604 3 "Cerebrum, Contusion, Single, NFS" 1 220069746308 "AIS 1998" 140624 4 "Cerebrum, Contusions, Mult, Bilat, Large" 1 220068517061 "AIS 1998" 140629 4 "Cerebrum, Hematoma, NFS" 1 220066261210 "AIS 1998" 140632 4 "Cerebrum, Hematoma, Epi/Extradural, Small" 1 220070098047 "AIS 1998" 140632 4 "Cerebrum, Hematoma, Epi/Extradural, Small" 1 220064632738 "AIS 1998" 140636 5 "Cerebrum, Hematoma, Epi/Extradural, Large" 1 220069716757 "AIS 1998" 140638 4 "Cerebrum, Hematoma, Intracerebral, NFS" 1 220066260699 "AIS 1998" 140640 4 "Cerebrum, Hematoma, Intracerebral, Small" 1 220068276145 "AIS 1998" 140648 5 "Cerebrum, Hematoma, Intracerebral, Large" 1 220068276370 "AIS 1998" 140652 4 "Cerebrum, Hematoma, Subdural, Small, Unilateral" 1 220068276145 "AIS 1998" 140652 4 "Cerebrum, Hematoma, Subdural, Small, Unilateral" 1 220066260699 "AIS 1998" 140660 3 "Cerebrum, Brain Swelling, NFS" 1 220072298252 "AIS 1998" 140662 3 "Cerebrum, Brain Swelling, Mild" 1 220069716757 "AIS 1998" 140662 3 "Cerebrum, Brain Swelling, Mild" 1 220069864323 "AIS 1998" 140678 4 "Cerebrum, Intraventricular Hemorrhage" 1 220069860051 "AIS 1998" 140678 4 "Cerebrum, Intraventricular Hemorrhage" 1 220068266891 "AIS 1998" 140678 4 "Cerebrum, Intraventricular Hemorrhage" 1 220069716757 "AIS 1998" 140684 3 "Cerebrum, Subarachnoid Hemorrhage" 1 end label values issregion issReg2 label def issReg2 1 "Head or neck", modify label def issReg2 6 "External", modify
Comment