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   vwiggins@stata.com (Vince Wiggins, StataCorp)
To   statalist@hsphsun2.harvard.edu
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
<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/



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