Home > Blockchain >  Extracting substring after comma
Extracting substring after comma

Time:02-28

I have a variable in Stata called place with entries that look like "Wichita, Kansas".

I want to split this variable into a city and state variable. The state always comes after a comma and a space.

CodePudding user response:

input str20(place)
"Wichita, Kansas"
"Salt Lake City, Utah"
"Buffalo, New York"
end

split place, p(",")

list

      --------------------------------------------------- 
     |                place           place1      place2 |
     |---------------------------------------------------|
  1. |      Wichita, Kansas          Wichita      Kansas |
  2. | Salt Lake City, Utah   Salt Lake City        Utah |
  3. |    Buffalo, New York          Buffalo    New York |
      --------------------------------------------------- 
  • Related