Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: collapsing string variables


From   Kevin McConeghy <kevinmcconeghy@gmail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index