Statalist The Stata Listserver


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

st: a question about number precision


From   "Jian Zhang" <[email protected]>
To   [email protected]
Subject   st: a question about number precision
Date   Fri, 31 Mar 2006 14:33:23 -0800 (PST)

Dear Stata Users,

I have a problem about number precision.  I cann't figure out what it 
happened.  Hope that you can help me out.  Thanks.

Here is the data:
ID
21557127 

then i run the following do file trying to extract the last three digits 
from the ID:

gen double temxxx=(ID/1000)
gen temyyy=int(temxxx)
gen temzzz=temxxx-temyyy
gen areaxxx=(temzzz*1000)
drop temxxx temyyy temzzz

the generated data looks like the following:
ID           areaxxx
21557127     127

However, when I typed: list if areaxxx==127, stata in fact listed nothing!

First I thought it may be because areaxxx is a floating-point variable, 
so I type: list if areaxxx=float(127).  However, Stata listed nothing 
again.  

Then I tried changing the do file a little bit:

gen double temxxx=(ID/1000)
gen temyyy=int(temxxx)
gen temzzz=temxxx-temyyy
gen areaxxx=float(temzzz*1000)
drop temxxx temyyy temzzz

after running the do file, the data is exactly same:
ID                areaxxx
21557127          127
However, when I typed list if areaxxx==127, stata listed nothing again!

I am really confused and could not figure out why stata treated the 
number this way.  Hope that you can help me out.  Thanks.

Jian Zhang



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