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: joining strings

From   Kevin McConeghy <>
Subject   st: joining strings
Date   Wed, 28 Nov 2012 10:00:10 -0600

Hello users,

I have a dataset with ~2.2 mill obs like so:

id        stringvar    + other variables
1          x
1          y
1          z
2          a
3          d
4          g
4          h

I was trying to combine the stringvar to collapse and make id a unique
key, like so:

id         stringvar
1          xyz
2          a
3          d
4          gh

with the following code:

quietly by id: gen x_ = cond(_N==1,0,_n)
egen x = concat(x_), p(_)
drop x_

reshape wide stringvar, i(id) j(x) string
egen str244 all_stringvar=concat(x1, x2, x3....)

Which worked for one quarter of data, but it takes a lot of computer
power with 1.9 obs and up to 100 unique string var for 1 obs
My computer wont calculate it for the whole dataset because it runs
out of memory

Is there some way to skip the reshape step and join string variables
by specifying the same id?:
egen stringvar_all = concat(stringvar), by id

Thanks for any help,
*   For searches and help try:

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