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

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

 From "William Buchanan" To Subject st: RE: problem with `r(min)' and `r(mean)' macros Date Mon, 28 Jan 2013 06:58:10 -0800

```Have you considered that the reason it doesn't work is because you don't
have any observations with a value exactly at the mean?  Instead try running
almost the exact same code with a few changes:

clear
set obs 10
ge id = _n
ge var1 = uniform()
qui: su var1
local LCmin =`r(min)'
local LCmean =`r(mean)'
local LCmax =`r(max)'
di `LCmean'
list

count if var1==`LCmin'
count if var1==`LCmean'
count if var1==`LCmax'

HTH,

Billy

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of mario fiorini
Sent: Monday, January 28, 2013 6:47 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: problem with `r(min)' and `r(mean)' macros

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 work with
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/
```