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, is already up and running.

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

Re: st: collapsing string variables

From   Nick Cox <>
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)


On Tue, Dec 11, 2012 at 5:19 PM, Kevin McConeghy
<> 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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index