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

st: numeric and string variables [was: Hello all & I'm sorry to do this again, but..]


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: numeric and string variables [was: Hello all & I'm sorry to do this again, but..]
Date   Sun, 19 Sep 2004 15:19:32 +0100

Jon Ebeling sent various mails arising from some 
confusion over getting Stata to show underlying
numeric information when a numeric variable has 
value labels associated. Jon also got confused 
between commands and functions. (Incidentally, 
please use informative titles in your postings.) 

As Renzo Comolli pointed out, the -nolabel- option 
is available in -tabulate- (and also in -list-, 
-edit-, etc.) for this need, so there is, it 
seems, no need to convert anything to anything else. 

In general, conversion syntax comes in pairs: 

1. The -encode- command takes a string variable and uses
it to generate a numeric variable with value labels. 
This is essential for some statistical commands 
which will not accept categorical variables held 
as strings, and often a good idea otherwise. 

-decode- does the reverse. 

2. -real()- and -string()- functions are brute 
force, direct ways of converting from one 
form to another. They appear within 
-generate- and -replace- commands. If you
know exactly what you're doing and do not 
fear loss of information, they may be the 
solution to your problem. 

3. -destring- and -tostring- are safer ways 
to go from string to numeric or numeric to string. 
Both can be applied to several variables and both have 
extra features to stop you losing information in your data
and to cope with common complications. 

There was a longer discussion of associated 
issues in "Speaking Stata: On numbers and strings", 
Stata Journal 2(3):314--329 (2002). 


*
*   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