Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Fraction 0.8 vs 0.8000001

From   Maarten Buis <>
Subject   Re: st: Fraction 0.8 vs 0.8000001
Date   Fri, 23 Dec 2011 16:47:20 +0100

On Fri, Dec 23, 2011 at 4:33 PM, qing ye  wrote:
> Why when I try to generate variable=(5-1)/5, stata cannot generate a
> variable equal to 0.8, the result the code generated is 0.8000001, why
> is this happening? How can I fix it?

No (binary) computer can store that number exactly. Computers store
numbers in binary and in binary a number like .8 is like 1/3 in
decimal: it cannot be represented in a finite number of digits. As a
consequence a computer has to round those numbers. This is an issue
that is often referred to as precision on this list and there is a lot
of useful material on it:

William Gould (2006) Mata Matters: Precision. The Stata Journal. 6(4):550-560.

Nicholas J. Cox (2006) "Stata tip 33: Sweet sixteen:
Hexadecimal formats and precision problems" The Stata
Journal, 6(2): 282-283.

Jean Marie Linhart (2008) "Mata matters: Overflow,
underflow and the IEEE floating-point format" The
Stata Journal, 8(2): 255-268.

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index