Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: precision problem using double
From
Stas Kolenikov <[email protected]>
To
[email protected]
Subject
Re: st: precision problem using double
Date
Sun, 16 Oct 2011 14:29:09 -0500
On top of NJC's response (which is on the spot, of course, as always),
another useful function is -reldif- along with -epsfloat-/-espdouble-
(which gives the relative accuracy, unlike the -smallestdouble- that
gives a number that is way too small to be relevant):
sysuse auto
sum gear_ratio
list if gear_ratio == 3.89
list if reldif(gear_ratio, 3.89) < 10*c(epsfloat)
This comes handy in comparisons with fixed known constants. Of course,
in your case, you should use -r(max)- which is a scalar with double
precision (2e-16) rather than -`r(max)'- which is a string; if the
latter is in scientific notation, it may have accuracy lower than
1e-15.
On Sat, Oct 15, 2011 at 1:37 AM, Leandro Brufman
<[email protected]> wrote:
> Been reading some stuff on the precision of double, and how Stata
> reads numbers for calculation (in particular this article
> http://www.stata-journal.com/sjpdf.html?articlenum=dm0022)
> But couldn't find a solution. Here's my problem:
>
> sum spread
> br if spread==`r(max)'
>
> * it returns that there are no observations.
>
> sum spread
> br if spread-`r(max)'<smallestdouble()
>
> *it also returns that there are no observations
>
> sum spread
> gen test=spread-`r(max)'
>
> * the minimum number of variable test is -2.84217094e-14
>
> any ideas on how to fix this code? i don't need a lot of precision,
> but I do need to have these two lines working fine:
> sum spread
> br if spread==`r(max)'
>
>
> as usual, many many thanks in advance...
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
--
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/