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

st: -charlist- available on SSC


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: -charlist- available on SSC
Date   Tue, 17 Dec 2002 19:07:29 -0000

Thanks to Kit Baum, the -charlist- program 
posted and discussed earlier today is now 
available from SSC. The output and syntax are changed 
from my original posting. 

In an up-to-date Stata, type 

. ssc desc charlist 

and if desired 

. ssc inst charlist 

For explanation of the -ssc- command, 
please see the first URL under my signature. 

Briefly, -charlist- shows which characters 
are present in a string variable. 

Here is a concocted example of one way 
in which it might be useful. 

Stata tells you that something which should be numeric 
is string, and -destring- won't play: 

. destring mystuff, replace
mystuff contains non-numeric characters; no replace

So you ask for a report: 

. charlist mystuff
123I

We see that "I" characters are present. 
Perhaps whoever typed in the data was 
distracted, or the OCR software made a mistake, 
so some "1" (one) characters have been entered 
as "I" (capital I). 

. l mystuff  if index(mystuff,"I") 

       mystuff
 12.       I23
 57.       I23
 73.       I23

You decide on appropriate surgery: 

. replace mystuff = subinstr(mystuff,"I", "1",.) 
(3 real changes made)

. destring mystuff, replace
mystuff has all characters numeric; replaced as byte

Of course, there are other ways to do 
this -- and also other examples in which
-charlist- may be useful. 

Nick 
n.j.cox@durham.ac.uk 
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index