Statalist


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

RE: st: RE: inconsistent response to same syntax


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: inconsistent response to same syntax
Date   Sun, 8 Jun 2008 16:16:11 +0100

I think you were right first time, i.e. the details of what is inside
the macro do not seem important in explaining your problem.

Nick 
[email protected]  

Gabi Huiber

It's just a set of variable names, like this:

global dates      "last_ar_payment next_bill curr_rate_exp strt stop"

The offending loop then does this, in the same do-file:

******* ******* put dates in Stata format

foreach k in ${dates} {
gen `k'=date(substr(`k'_date,1,10),"mdy")
drop `k'_date
rename `k' `k'_date
format `k'_date %d
}

Then in the second do-file I am trying to do this:

foreach k in $dates {
gen `k'_sunday=`k'_date-dow(`k'_date)
drop `k'_date
format `k'_sunday %d
}

But the curly bracket syntax doesn't work anymore. I need to use
$dates like above.


On 6/6/08, Nick Cox <[email protected]> wrote:
> You are omitting some details that might be the key to the question.
>  What is in this problematic global?
>
 Gabi Huiber
>
>  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.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index