Researcher2
Researcher2

Reputation: 23

RegEx - String Help - Stata

I have data in the form of

name1, name2, name3, name4

all in one column. I'm trying to separate all names into their own columns.

So far I have:

gen Songwriter1 = regexs(1) if regexm(Songwriter, "(.*)[,]") 

which gives all values before the ","

Is there a way to specify that I want the value between the first "," and the second ","? And so forth?

Upvotes: 2

Views: 241

Answers (1)

Ro Yo Mi
Ro Yo Mi

Reputation: 15000

If you have Stata 8 or later you could try:

split Songwriter, p(,) 

split given Songwriter and p(,) will parse (split) on commas and throw those commas away. It will create Songwriter1, Songwriter2, etc.

Upvotes: 2

Related Questions