Statalist The Stata Listserver


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

st: RE: a question about number precision


From   "Alex Ogan" <[email protected]>
To   <[email protected]>
Subject   st: RE: a question about number precision
Date   Fri, 31 Mar 2006 17:44:33 -0500

Here's something weird and probably related: 

. clear

. set obs 1
obs was 0, now 1

. gen ID = 21557127

. display ID
21557128

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Jian Zhang
Sent: Friday, March 31, 2006 5:33 PM
To: [email protected]
Subject: st: a question about number precision

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/


This message is intended solely for the designated recipient(s). It may contain confidential or proprietary information and may be subject to confidentiality protections. If you are not a designated recipient, you may not review, copy, or distribute this message. If you receive this in error, please notify the sender by reply e-mail and delete this message. 

Arrowstreet Capital, L.P. is an Equal Opportunity Employer. 



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