Hello I saw some people have asked before about how to collapse
strings as the command is really for numerics, but I had trouble
following the code examples. I attached an excel sheet showing my data
setup as is and what I need to do.
My understanding is that this can be done using by: statements or some
nifty merging.
The basic problem is this:
id drugid drug1 drug 2 drug 3
1 1 A
1 2 B
2 1 A
2 2 B
2 3 C
And I want to collapse to: (I dont need drugid after I collapse).
id drug drug2 drug 3
1 A B
2 A B C
I was trying figure out how this merge example works from a previous
post, but I am open to any method:
save orig
duplicates drop id, force
keep id org_name
save temp_name, replace
use orig, clear
collapse (sum) _*, by(id)
merge id using temp_name, sort
Thanks for any help!
Kevin
Kevin McConeghy, PharmD
Attachment:
collapse_example.xlsx
Description: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet