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   daniel klein <[email protected]>
To   [email protected]
Subject   Re: st: Combining strings by group
Date   Wed, 16 Nov 2011 10:41:49 +0100

Ben,

try a combination of -reshape- and -egen-'s -concat()- function.

. bys code : g byte j = _n
. reshape wide type ,i(code) j(j)
. egen combinedtype = concat(type*) ,p(" ")
. replace combinedtype = subinstr(combinedtype, " ", ", ", .)
. drop j type* // clean up

Best
Daniel

-- 
[...]
Assume I had the following dataset with two variables:

code	type
1	a
1	c
2	e
3	f
3	g	
3	z

I want to create a third (string) variable that concatenates the string
"type" by code group, [...]

code	combinedtype
1	"a, c"
2	"e"
3	"f, g, z"
*
*   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