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]

RE: st: Combining strings by group


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Combining strings by group
Date   Wed, 16 Nov 2011 10:56:56 +0000

Correct. Thanks for the fix. I fixed the code when testing it but did not correct my draft. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of daniel klein
Sent: 16 November 2011 10:48
To: [email protected]
Subject: Re: st: Combining strings by group

Smart code, Nick. I especially like the idea of using -by- instead of
-bysort- in the second line, since the data is already sorted. I
usually use -bysort- without thinking about it's need. However, I
think there is one typo in the code.

I guess the first line

bysort code : replace type = type[_n-1] + "," + type if _n > 2

should read

bysort code : replace type = type[_n-1] + ", " + type if _n > 1

Since the required data structure only has one row per case, I would
further replace

by code : replace type = type[_N]

with

by code : keep if (_n == _N)

(Ben, to perfectly match your example, you will need an additional -rename-.)

Best
Daniel

--
It's easier than that.

bysort code : replace type = type[_n-1] + "," + type if _n > 2
by code : replace type = type[_N]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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