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]
Re: st: collapsing string variables
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: collapsing string variables
Date
Tue, 11 Dec 2012 17:46:18 +0000
On principle I am ignoring your attachment. As was mentioned very
recently, you should not send attachments to Statalist. This is
explained in the FAQ.
You can call what you want collapsing if you like but it's not among
the purposes of the -collapse- command, which is to make a dataset of
summary statistics.
This works for your data here:
reshape long drug , i(id drugid)
drop if missing(drug)
drop _j
reshape wide drug, i(id) j(drugid)
Nick
On Tue, Dec 11, 2012 at 5:19 PM, Kevin McConeghy
<[email protected]> wrote:
> 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
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/