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]

st: Combining strings by group

From   "Ben Hoen" <>
To   <>
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

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

*   For searches and help try:

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