Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: collapsing string variables


From   Kevin McConeghy <[email protected]>
To   [email protected]
Subject   st: collapsing string variables
Date   Tue, 11 Dec 2012 11:19:58 -0600

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



© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index