0

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.

enter image description here

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:

enter image description here

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!!

1 Answer 1

0

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 |
     +----------------------------+
2
  • Thank you very much for your answer! There is still a quastion. Should I run replace only with "V" in the DO, or should I replace it with some variable? Commented May 12, 2022 at 11:43
  • Sorry, but I don’t understand what else you’re asking.
    – Nick Cox
    Commented May 12, 2022 at 12:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.