This is off a bit from the discussion on the table, but I'll point out
that in cases where one needs the construction (something == 1 |
something == 2 | ... ), the inlist() function can save some typing.
So you could do something like:
. local buicks `" "Buick Century","Buick Electra","Buick Opel" "'
. local datsuns `" "Datsun 200","Datsun 210" "'
. local vws `" "VW Dasher","VW Rabbit","VW Scirocco" "'
. local brands "buicks datsuns vws"
. foreach b of local brands {
. list make price if inlist(make,``b'')
. }
(Note the double set of single-quotes around the b macro. The first set
substitutes the word "buick", "datsun", or "vws" for "b"; the second set
then expands that name to the relevant macro.
In general it seems like the inlist() function--and inrange()--are
under-publicized.
--Nick Winter
> -----Original Message-----
> From: Steichen, Thomas [mailto:[email protected]]
> Sent: Thursday, June 27, 2002 10:07 AM
> To: [email protected]
> Subject: st: RE: getting the quotes right
>
>
> 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
>
*
* 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/