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

st: RE: RE: getting the quotes right


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: getting the quotes right
Date   Thu, 27 Jun 2002 15:19:04 +0100

Steichen, Thomas
>
> Bill Gould followed up on a question from H�kon Finne and proposed:
>
> > What H�kon needs to have in `brands' is
> >
> > `"(make=="Buick Century" | make=="Buick Electra" | make=="Buick Opel")"'
> > `"(make=="Datsun 200" | make=="Datsun 210")"'
> > `"(make=="VW Dasher" | make=="VW Rabbit" | make=="VW Scirocco")"'
>
> This, unfortunately, leads to the dreaded macro length problem,
> as these commands show:
>
> . local buicks  `"(make=="Buick Century" | make=="Buick Electra"
> | make=="Buick Opel")"'
> . local datsuns `"(make=="Datsun 200" | make=="Datsun 210")"'
> . local vws     `"(make=="VW Dasher" | make=="VW Rabbit" |
> make=="VW Scirocco")"'
> . local brands  `"`buicks'"' `"`datsuns'"' `"`vws'"'
> .
> . foreach brand of local `"`brands'"'  {
>   2. list price if `brand'
>   3. }
> local macro name "(make=="Buick Century" | make=="Buick Electra"
> | make=="Buick Opel") too long
> r(198);
> .
>
> In this case, the macro length problem appears to be due
> to some internal problem in how -foreach- is handling macros.
>
> StataCorp, is there a solution?
>
> Tom Steichen
>

I believe the error here is not a bug, but a slip by Bill in
how the -foreach- is invoked: it should start

foreach brand of local brands {

That is, -foreach- works by indirection with this syntax. The user
specifies the name of a local and then -foreach- looks
inside that local for the elements of the list.

As you will see, Stata is objecting to the _name_, not
the contents.

Nick
[email protected]

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