Statalist


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

Re: st: RE: trimming leading numbers from a string.


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   Re: st: RE: trimming leading numbers from a string.
Date   Tue, 23 Sep 2008 12:36:38 +0530

cool.

Thanks.

On Tue, Sep 23, 2008 at 12:23 PM, Philip Ryan
<[email protected]> wrote:
>
> Try:
>
> gen cname_2 = trim(regexr(trim(cname), "^[0-9]", ""))
>
>
> http://www.ats.ucla.edu/stat/stata/faq/regex.htm  is especially helpful
>
>
> Phil
>
>
>
> At 03:28 PM 23/09/2008, you wrote:
>>
>> ahhh I get you. I was thinking more in terms of "detecting" a number
>> and replacing it with a space and then trimming. But Thank You for
>> your reply.
>>
>> Is there a way to say ALL except the 1st word ? That would be very
>> useful cos sometimes I  have " 0 Andhra Pradesh ".
>>
>> Thank you,
>> Ashim.
>>
>> On Tue, Sep 23, 2008 at 11:13 AM, Matt Spittal
>> <[email protected]> wrote:
>> > Ashim,
>> >
>> > You can use the string functions, see -help string functions- to extract
>> > the information that you want. For instance
>> >
>> >        generate place = word(cname, -1)
>> >
>> > will return the last word in the variable cname. Similarly,
>> >
>> >        generate place = word(cname, 2)
>> >
>> > will return the second word (although this may not be what you want as
>> > there is only one word in your first example).
>> >
>> > -- Matt
>> > [email protected]
>> >
>> >
>> > -----Original Message-----
>> > From: [email protected]
>> > [mailto:[email protected]]On Behalf Of Ashim Kapoor
>> > Sent: Tuesday, 23 September 2008 3:07 PM
>> > To: [email protected]
>> > Subject: st: trimming leading numbers from a string.
>> >
>> >
>> > Hello everyone,
>> >
>> >
>> > I have a string variable called "cname".
>> >
>> > It looks something like this.
>> >
>> >                 cname
>> > 1.        DELHI
>> > 2.    0 HYDERBAD
>> > 3.    1 USA
>> > 4.     4 AP
>> >
>> > I want to remove the leading 0 / 1 / 4 / other numbers from this
>> > string and keep only the alphabets. Is there a do file someone has
>> > written on this ?
>> >
>> > Thank you,
>> > Ashim.
>
> Philip Ryan
> Discipline of Public Health
> University of Adelaide 5005
> South Australia
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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