In answering Ernest Berkhout's question about -foreach-, Nick Cox
<n.j.cox@durham.ac.uk> asked whether e(), r(), and s() results are always
evaluated in an expression,
> [...]
> r(list)
>
> will be evaluated by Stata to its value, but usually (always???)
> that is to the right of an = sign.
Yes, always.
Formally, we would say that what follows an "=" sign is evaluated in an
"expression context", and expressions understand e(), r(), and s() results.
What follows an "=" (e.g. in a -generate-, -replace-, -local-, [weight], etc.)
is clearly an "expression context", but there are others -- what falls in the
parenthesis of a -post-, in -display-, and some others. As Nick noted,
expressions are not understood everywhere and in particular not in a -foreach-
command. This is because expressions support such a rich syntax that it would
be impossible to parse the rest of the command. Unless a command indicates
that an expression is understood in a particular context, by placing an
italicized exp in the syntax diagram, then expressions are not allowed by the
command.
Returning to Nick's example, note that r(list) evaluates to a string. So, if
we want to use it in an expression context, and have that expression make
sense, then r(list) better appear where a string is expected, e.g.
-substr(r(list), 1 10)-.
-- Vince
vwiggins@stata.com
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/