[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Help: typo-error in for-loop or more serious problem??
In answering Ernest Berkhout's question about -foreach-, Nick Cox
<email@example.com> asked whether e(), r(), and s() results are always
evaluated in an expression,
> will be evaluated by Stata to its value, but usually (always???)
> that is to the right of an = sign.
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)-.
* For searches and help try: