Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to destring variables containing char " ' "


From   Roger Newson <[email protected]>
To   [email protected]
Subject   Re: st: how to destring variables containing char " ' "
Date   Wed, 14 Apr 2004 18:35:50 +0100

At 12:49 14/04/04 -0400, Shourun Guo wrote:
I have a hard time to destring some variables with both characters and numbers. The numbers are what I want. The characters may contain " ' ". If I include this character in the option of ignore, I will get error message of mismatch type. If I don't, I will be reminded that the conversion won't be done because some non-numeric character (I am sure it is the " ' ")exists. It seems that the STATA confuses the double quotation and the single quotation. Any suggestions.

Yes. If your string variable is called -netty-, and you want your numeric variable to be called -nutty-, then you can convert in 2 stages by substituting another character for the "'" in -netty-. For instance, if you type

gene natty=subinstr(netty,"'","@",.)
destring natty, ignore("@") gene(nutty)

then -natty- will be like -netty-, except that all the "'" characters will be replaced by "@" characters, and -nutty- will be the numeric variable that you wanted to create.

I hope this helps.

Roger


--
Roger Newson
Lecturer in Medical Statistics
Department of Public Health Sciences
King's College London
5th Floor, Capital House
42 Weston Street
London SE1 3QD
United Kingdom

Tel: 020 7848 6648 International +44 20 7848 6648
Fax: 020 7848 6620 International +44 20 7848 6620
or 020 7848 6605 International +44 20 7848 6605
Email: [email protected]
Website: http://www.kcl-phs.org.uk/rogernewson

Opinions expressed are those of the author, not the institution.

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index