Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: inconsistent response to same syntax


From   "Zurab Sajaia" <zsajaia@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: inconsistent response to same syntax
Date   Fri, 6 Jun 2008 12:09:22 -0400

Gabi,
Questions about command parsing can be answered best by the folks at StataCorp I guess ...
but I'd think your problems might be related to the line-by-line command reading, to figure out how to run a loop,
Stata reads (my assumptions) the line from word "foreach" till the first "{" sign, and then evaluates that line for different possible syntaxes
like in, of varlist, of local, of global etc, so allowing another pair of {} might make this very difficult or impossible (imagine global containing some more symbols like { or }) ...

Again, there might be another explanation but I personally prefer to think that although Stata is very smart, it can't always guess what I mean or want so I try not to confuse it :)

Best,
Zurab




----- Original Message ----- From: "Gabi Huiber" <ghuiber@gmail.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Friday, June 06, 2008 11:40 AM
Subject: Re: st: Re: inconsistent response to same syntax



Thank you. My main concern was to use the same syntax everywhere in
case I ever have to parse these do-files in some automatic fashion.
Your solution will do it nicely.

But it's still unclear what causes the inconsistency in the first
place, and I'm curious.

Thanks again,

Gabi


On 6/6/08, Zurab Sajaia <zsajaia@hotmail.com> wrote:
In this case it might be better to use different syntax of -foreach-

 foreach k of global dates {
 }


 ----- Original Message ----- From: "Gabi Huiber" <ghuiber@gmail.com>
 To: <statalist@hsphsun2.harvard.edu>
 Sent: Friday, June 06, 2008 11:03 AM
 Subject: st: inconsistent response to same syntax



> Hello listers,
>
> I got into the habit that I use the ${globalmacro} syntax instead of
> the plain $globalmacro, on the chance that I sometimes have to combine
> such macro names within other macro or variable names.
>
> But this syntax sometimes elicits an error message from Stata, like so:
>
> foreach k in ${dates} {
> program error:  code follows on the same line as open brace
> r(198);
>
> At other times, Stata doesn't mind. In this particular example I
> declared the ${dates} macro in one do-file, and used it with foreach
> as shown above within the same do-file without a problem.
>
> Then another do-file called and executed the first do-file, and later
> attempted to make use of the same ${dates} macro in another foreach
> construct. It was this second time that I got the error response
> above.
>
> The syntax $dates in this second foreach loop is accepted and all is
> well. But I can't find any reason for this inconsistency. Both
> syntaxes should always work.
>
> Any ideas?
>
> Thank you,
>
> Gabi
> *
> *   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/
>
>
 *
 *   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/

*
*   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/

*
*   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