Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Another question regarding string variables
From
Kieran McCaul <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Another question regarding string variables
Date
Wed, 27 Feb 2013 12:58:13 +0800
....
You can do this with regular expressions:
clear *
input str20 name
"John Howard R"
end
gen first = regexs(1) if regexm(name, "([a-zA-Z]+)[ ]*([a-zA-Z]+)[ ]*[a-zA-Z]")
gen last = regexs(2)+ " " +regexs(3) if regexm(name, "([a-zA-Z]+)[ ]*([a-zA-Z]+)[ ]*([a-zA-Z])")
list
or you could do it with the word() function:
clear *
input str20 name
"John Howard R"
end
gen first = word(name,1)
gen last = word(name,2)+ " " +word(name,3)
list
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Michael Stewart
Sent: Wednesday, 27 February 2013 11:55 AM
To: statalist
Subject: st: Another question regarding string variables
Hi,
I am sorry to keep bothering you regarding string variables
I am trying to find if there is a function to split a string "Howard
James R" --> "Howard" & ("James R")
If I use Split, I would get Howard, James and R which is not what I want
I want to split the string after the first word into two string
variables first variable containing first word and second variable
containing rest of the string
--
Thank you ,
Yours Sincerely,
Mike.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/