How's this...?
gen surname = word(name, wordcount(name))
gen inits =
trim(reverse(subinword(reverse(name),reverse(surname),"",1)))
gen newname = trim(surname + " " + inits)
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Rajesh
Tharyan
Sent: 15 May 2006 17:01
To: [email protected]
Subject: st: string manipulation
Hi all,
I have a list of names in the following format
A K Nath
B G G goldfinger
G gomes
R raja micheal
Lothar
I need to get them in the following format
Nath A K
Goldfinger B G G
Gomes G
Micheal R raja
Lothar
if they were all of the same length I could use the substr function to
do this without any problem. With different lengths and different number
of forenames I am not sure
But, This is what I have been thinking
1. If there is way to find out the position of the last space then I
could use that info to split the names into forenames and surname 2.
then concat them in the way I require 3. Since the number of forenames
Am I right? How do I get the position of the last space. I know Index
will give me the location of the first instance of a character is there
something similar location of the last instance? Or to start looking
from the back?
I am using Stata 8.2
Thanks
rajesh
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/