 Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: precision problem using double

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: precision problem using double Date Sat, 15 Oct 2011 08:49:58 +0100

```Try using r(max).

`r(max)' is a string representation of r(max) and uses decimal
characters only. For a fraction you could lose important detail.
Emphasis on "could". For testing equality, r(min) and r(max) are
advisable rather than `r(min)' and `r(max)', as the difference between
them can bite in that context.

For your kind of problem, -sort-ing the non-missings and selecting the
highest is another way to do it.

. set obs 10
obs was 0, now 10

. gen foo  = runiform()

. su foo

Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
foo |        10    .4841855    .2786673   .0610638   .8714491

. l if foo == `r(max)'

+----------+
|      foo |
|----------|
10. | .8714491 |
+----------+

. l if foo == `r(min)'

. l if foo == r(min)

+----------+
|      foo |
|----------|
8. | .0610638 |
+----------+

Nick

On Sat, Oct 15, 2011 at 7:37 AM, Leandro Brufman
<leandrobrufman@gmail.com> wrote:
> Been reading some stuff on the precision of double, and how Stata
> http://www.stata-journal.com/sjpdf.html?articlenum=dm0022)
> But couldn't find a solution. Here's my problem:
>
>
> * it returns that there are no observations.
>
>
> *it also returns that there are no observations
>
>
> * 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: