Reputation: 1
I am trying to rearrange the identification data (ID) that is duplicated. Each ID is duplicated, because the person uses more than one drug type.
Each code represents the name of the drug and in each column titled (drug1
; drug2
; drug3
) there is information if the person takes (1) or does not take (0)
Into:
As the code is the name of the drug (drug1= code 17
; Drug2 = code 5
; Drug3 = code 3
), when remodeling the code column it would not appear in the database
I think using reshape
will not achieve the result I expect.
I would be very grateful for the help!!
Upvotes: 0
Views: 43
Reputation: 37278
I don't fully understand your rules or example but this may help.
clear
input ID Code Drug1 Drug2 Drug3
1 5 0 1 0
1 17 1 0 1
2 17 1 0 1
2 5 0 1 0
2 3 0 0 3
end
collapse (max) Drug?, by(ID)
list
foreach v of var Drug? {
replace `v' = `v' > 0
}
list
+----------------------------+
| ID Drug1 Drug2 Drug3 |
|----------------------------|
1. | 1 1 1 1 |
2. | 2 1 1 1 |
+----------------------------+
Upvotes: 0