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

# Re: st: problem with `r(min)' and `r(mean)' macros

 From mario fiorini To statalist@hsphsun2.harvard.edu Subject Re: st: problem with `r(min)' and `r(mean)' macros Date Mon, 28 Jan 2013 16:14:24 +0100

```thanks Nick,
I could sense it was a precision issue, but I was very confused
because it was only there for `r(min)' and not `r(max)'. [and sorry
for the obviously stupid `r(mean)' check].
now I understand both precision issues.

Mario

On 28 January 2013 16:01, Nick Cox <njcoxstata@gmail.com> wrote:
> This is a precision issue, biting you twice over.
>
> First off, there is a loss of precision possible with using e.g.
> `r(min)' rather than r(min) which is roughly parallel to the lower
> precision of macros compared with scalars.
>
> !!! Don't use local macros if you seek maximum precision with non-integers. !!!
>
> Second, testing for exact equality can be tricky at the best of times
> for reasons often rehearsed on this list and elsewhere.
>
> . search precision
>
> in an up-to-date Stata and start with Bill Gould's blog postings.
>
>
> set obs 1000
> gen var1 = runiform()
> su var1
> scalar max = r(max)
> scalar min = r(min)
> count if var1 == max
> count if var1 == min
>
> Whether the mean of random numbers on the unit interval is equal to
> any particular random number is surely of less interest.
>
> Nick
>
>
> On Mon, Jan 28, 2013 at 2:47 PM, mario fiorini <mariofiorini73@gmail.com> wrote:
>> Dear statalist,
>> I am summarising a variable and then trying to use the `r(.)' macros
>> However, in some instances Stata does not seem to find any variables
>> that take the `r(min)' and `r(mean)' values. For some reason, it does
>> The code below should clarify the problem. When I run it, I always get
>> that no observation takes the min or the mean (why???), but there is
>> an observation that takes the max.
>> The problem does not depend on whether I use the original `r(min)' or
>> a macro=`r(min)'.
>> If it matters I am using a mac osx 10.8 with Stata 12.1 MP.
>> Any hint would be appreciated because it is driving me crazy.
>> Mario
>>
>>  // Start
>> clear
>> set obs 1000
>> ge id = _n
>> ge var1 = uniform()
>> su var1
>> local LCmin =`r(min)'
>> local LCmean =`r(mean)'
>> local LCmax =`r(max)'
>>
>> count if var1==`LCmin'
>> count if var1==`LCmean'
>> count if var1==`LCmax'
>>  // Ends
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```