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]
Re: st: editing string variables to remove letters and keep only numbers
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: editing string variables to remove letters and keep only numbers
Date
Tue, 18 Jun 2013 00:11:00 +0100
Nick
[email protected]
On 18 June 2013 00:05, Darren White <[email protected]> wrote:
> Hi
>
> I would use "destring" with the " force" option (which would return you a variable with only the numeric IDs).
> You could then remove those IDS from your string vars (using if conditions) , perform your routine (below) then bring back the non-alpha prefixed id's from your destring variable.
>
> Darren
>
>
>
> Darren White BSc MPH
> Epidemiologist
> Preventive Health Unit
> Chief Health Officer Branch
> Department of Health
> Butterfield Street
>
> Herston 4006
> Brisbane
>
> ph: (07) 3328 9288
> mobile:0407 094 595
> Email: [email protected]
>
>
>
>>>> Michael McCulloch <[email protected]> 6/18/2013 8:53 am >>>
> I have a variable in my dataset that (due to changes in data entry practices over time) contains several styles of the variable ID:
>
> - a number (e.g. 164)
> - a letter-number combination (e.g. e64)
> - a comma-separated letter-number combination (e.g. e64,e65)
>
> In seeking to (A) remove the letters, and (B) separate the comma-separated into two separate variables, ID1 and ID2, I wrote the following argument:
>
> . split ID, p(",")
> . gen str id1_new =""// make new ID to separate out the "e" from ID
> . replace id1_new=substr(id1,2,3)
>
>
> This successfully splits ID into ID1 and ID2.
>
> This also works if:
> a 3-digit variable has a preceding letter (e64 is changed to 64)
>
> However, in the case of a 3-digit values WITHOUT PRECEDING LETTER, the first digit is removed (164 is changed to 64).
>
> Any suggestions would be appreciated.
>
>
> Best wishes,
> Michael McCulloch, LAc MPH PhD
>
> --
> Pine Street Foundation, since 1989
> 124 Pine Street | San Anselmo | California | 94960-2674
> P: (415) 407-1357 | F: (206) 338-2391 | http://www.PineStreetFoundation.org
>
>
> *
> * 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/
>
>
> ********************************************************************************
> This email, including any attachments sent with it, is confidential and for the sole use of the intended recipient(s). This confidentiality is not waived or lost, if you receive it and you are not the intended recipient(s), or if it is transmitted/received in error.
> Any unauthorised use, alteration, disclosure, distribution or review of this email is strictly prohibited. The information contained in this email, including any attachment sent with it, may be subject to a statutory duty of confidentiality if it relates to health service matters.
> If you are not the intended recipient(s), or if you have received this email in error, you are asked to immediately notify the sender by telephone collect on Australia +61 1800 198 175 or by return email. You should also delete this email, and any copies, from your computer system network and destroy any hard copies produced.
> If not an intended recipient of this email, you must not copy, distribute or take any action(s) that relies on it; any form of disclosure, modification, distribution and/or publication of this email is also prohibited.
> Although Queensland Health takes all reasonable steps to ensure this email does not contain malicious software, Queensland Health does not accept responsibility for the consequences if any person's computer inadvertently suffers any disruption to services, loss of information, harm or is infected with a virus, other malicious computer programme or code that may occur as a consequence of receiving this email.
> Unless stated otherwise, this email represents only the views of the sender and not the views of the Queensland Government.
> **********************************************************************************
>
>
> *
> * 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/