sorry I though you wanted the last part of the string!
----- Original Message -----
From: "Marcela Perticara" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 07, 2005 10:56 AM
Subject: st: Re: substring help
> Heather
>
> Something that should work
>
> gen str2 state=reverse(substr(reverse(cntyname),1,2))
>
> There must be an easiest way, but I always choose the less efficient one!
>
> Other options are
>
> gen str2 state=substr(cntyname,index(cntyname," ")+1,2)
>
> or
>
> gen str2 state=word(cntyname,2)
>
> but these won�t work if there is another space in the name of the county.
>
>
> Marcela
>
> ----- Original Message -----
> From: "Heather Gold" <[email protected]>
> To: <[email protected]>
> Sent: Tuesday, June 07, 2005 10:32 AM
> Subject: st: substring help
>
>
> > Dear Fellow Listers -
> >
> > Someone has probably figured this out previously, but I can't seem to
find
> > exactly what I need in the archives or help...
> >
> > I have a string variable with county and state names merged as one
string
> > 15 characters long. I need to get rid of the trailing state name.
> > For example, I have:
> >
> > Genesee NY
> > Bronx NY
> > Queens NY
> >
> > And I want to have only:
> > Genesee
> > Bronx
> > Queens
> >
> > I tried
> > gen cnty=substr(cntyname, -2,2)
> >
> > But that does the "opposite" of what I want, ie, returns "NY".
> > Because the county name varies in length, I can't just do a substring of
a
> > specific length, starting from the beginning of the variable.
> >
> > Shouldn't there be an obvious solution? I can't find it.
> >
> > Thanks,
> > Heather
> >
> >
> > *
> > * 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/
*
* 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/