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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: r(varlist)


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: r(varlist)
Date   Thu, 8 Nov 2012 21:57:13 +0000

r() results and e() results have a dual personality. For example,
returned scalars can often be treated _as if_ they were (local)
macros, but it is at best a gross over-simplification to say that they
_are_ macros.

. sysuse auto
(1978 Automobile Data)

. su mpg

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
         mpg |        74     21.2973    5.785503         12         41

. ret li

scalars:
                  r(N) =  74
              r(sum_w) =  74
               r(mean) =  21.2972972972973
                r(Var) =  33.47204738985561
                 r(sd) =  5.785503209735141
                r(min) =  12
                r(max) =  41
                r(sum) =  1576

. di r(min)
12

. di `r(min)'
12

. di "`r(min)'"
12

Note that the " " emphasise a string interpretation, which may not
however make a difference to what you see.

On Thu, Nov 8, 2012 at 9:28 PM, Cohen, Elan <cohened@upmc.edu> wrote:

I think what Tashi is questioning is the fact that typically a local
needs to be surrounded by `' in order to be evaluated.  But the macro
-r(varlist)- does not.

Steve Nakoneshny

Tongue in cheek comments aside, you would also need to enclose the
called macro as -di `a'- in order to have Stata evaluate the macro. If
what you wanted to do was display the contents of the macro (rather
than evaluate the macro) you would have to nest it in double quotes
-di "`a'"- much as Maarten explained earlier.

On 2012-11-08, at 2:12 PM, Steve Nakoneshny wrote:

>> Keystroke error?
>> You defined your local as x, not a.

On 2012-11-08, at 2:07 PM, tashi lama wrote:

>>> Ok.That explains we need to wrap `r(varlist)' with " " to display the strings. However,
>>> sysuse auto
>>> ds
>>> di r(varlist) shouldn't have given     make price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
>>> for eg.
>>> local x "Make"   // x is a macro
>>> di a
>>> a not found
>>>
>>> di a doesn't work but di r(varlist) works although both a and r(varlist) are macros. Please explain.
*
*   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/


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