Statalist


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

Re: st: finding non-numeric characters before I can destring


From   Michael McCulloch <[email protected]>
To   [email protected]
Subject   Re: st: finding non-numeric characters before I can destring
Date   Thu, 18 Oct 2007 08:52:56 -0700

Thanks Ben, this worked well to identify records containing nonnumeric characters.
I implemented your suggestion using:
gen byte notnumeric = real(number)==. /*makes indicator for obs w/o numeric values*/
tab notnumeric /*==1 where nonnumeric characters*/
list number if notnumeric==1 /*will show which have nonnumeric*/





Type

gen byte notnumeric = real(number)==.

to compute an indicator for the obs without numeric values.

Alternatively, if you want to define flexible rules for valid imputs,
you can use regular expressions, e.g.

gen byte notnumeric = regexm(number, "^[-+]?[0-9]*\.?[0-9]+$")==0

See, e.g., http://www.regular-expressions.info/ on regular expressions.

ben

On 10/18/07, Michael McCulloch <[email protected]> wrote:
 Hello,
 I've got a field that's supposed to be all numbers but due to keying
 errors may contain letters. How can I find those records?

 What I've done:
         . destring number, replace

 Error message:
         number contains non-numeric characters; no replace

 Thank you,
 Michael

 --

 Michael McCulloch
 Pine Street Foundation
 124 Pine St., San Anselmo, CA 94960-2674
 Tel:    (415) 407-1357
 Fax:    (415) 485-1065
 [email protected]
 *
 *   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/



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