Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Help: typo-error in for-loop or more serious problem??

From (Vince Wiggins, StataCorp)
Subject   Re: st: Help: typo-error in for-loop or more serious problem??
Date   Mon, 24 Feb 2003 13:26:31 -0600

In answering Ernest Berkhout's question about -foreach-, Nick Cox
<> 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

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

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index