Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: string manipulation


From   "Rajesh Tharyan" <R.Tharyan@exeter.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: string manipulation
Date   Mon, 15 May 2006 17:43:20 +0100

Hi,
That works.. brilliant 
thanks
rajesh

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Harrison
Sent: 15 May 2006 17:24
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: string manipulation

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: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Rajesh
Tharyan
Sent: 15 May 2006 17:01
To: statalist@hsphsun2.harvard.edu
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/

*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index