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

st: Re: a question on function int

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: a question on function int
Date   Wed, 19 Oct 2005 16:45:28 -0400

It has nothing to do with the int() function, it has to do with precision. temzzz does not contain .005, but instead 0.0049999998882.... Try -search precision- and check out the various FAQs at the end to learn more. You can sometimes address these problems by using doubles instead of floats. In other cases you can use the float() function and sometimes just using round() works. In your case, I would keep long integer IDs as string variables to avoid precision issues and allow easier access to extracted segments.

Michael Blasnik

----- Original Message ----- From: "Jian Zhang" <>
To: <>
Sent: Wednesday, October 19, 2005 4:30 PM
Subject: st: a question on function int


I have a question about the function int that I could not understand what
stata is doing.  Hope that you can answer me.  Thanks.

Here it is:

For example, I have a data set:

after I run the following commands:

gen double temxxx=(id/1000)
gen temyyy=int(temxxx)
gen temzzz=temxxx-temyyy
gen areaxxx=int(temzzz*1000)
list id temxxx temyyy temzzz areaxxx

What I got is
id         temxxx         temyyy    temzzz  areaxxx
10103005   10103.005      10103     .005      4

Is variable areaxxx supposed to be 5? Why did stata give me 4 instead of
5? Any clue for this?


*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index