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

st: RE: question on datatypes


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: question on datatypes
Date   Thu, 20 Oct 2005 10:25:08 +0100

This is a frequent question on Statalist. 

If you what are reading in, although it looks
like a standard numeric variable with a decimal
point, is really some kind of identifier or 
code, then I think by far the safest strategy 
is to read it in as a string variable and 
then do string manipulations on it. This can 
include removing the point. 

Even if you read it in as -float- and then convert
to -long- it is all too likely that errors will
be introduced in the last digit or so. 

As a thread yesterday advised, -search precision-
and look at the FAQs there mentioned. The underlying
issue is that computers are really doing calculations
in binary, not decimal. A massive amount of cleverness goes into
hiding this fact from the user, and even the programmer, 
but it is inescapable and on occasions can bite you. 

Nick 
[email protected] 

NEYMOTIN, FLORENCE
 
> I have variables that are coded in  
> as 2-3 digits and 6 decimal places 
> after that, e.g. 150.089873 and I want to convert this to get 
> rid of the decimal places so it 
> looks like 150089873 but when I just multiply by 1000000 then 
> it keeps storing it as a "float" 
> display i.e. 1.5E8 and more than that, the last decimal 
> places are actually INCORRECT in the new 
> version...it will say 1.50089875 instead...which is 
> INCORRECT.  I am using Stata 8 and that is 
> where this problem occurs.  I was wondering what the easiest 
> way is to change datatypes that 
> something is input in so that it will not be a problem.

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