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: Combining strings by group


From   "Ben Hoen" <bhoen@lbl.gov>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Combining strings by group
Date   Tue, 15 Nov 2011 23:58:49 -0500

I can't seem to figure out how to concatenate strings for groups of
variables.

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, which would produce the following output (the quotes
are to indicate a string variable):

code	combinedtype
1	"a, c"
2	"e"
3	"f, g, z"

Therefore for each code group (1, 2 and 3), the type is concatenated with
commas separating each type.

Any ideas?




Ben Hoen
Principal Research Associate
Lawrence Berkeley National Laboratory
Office: 845-758-1896
Cell: 718-812-7589
bhoen@lbl.gov
http://eetd.lbl.gov/ea/emp/staff/hoen.html



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index