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 Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: getting the quotes right
Date   Thu, 27 Jun 2002 11:16:08 -0400

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:STEICHT@RJRT.com] 
> Sent: Thursday, June 27, 2002 10:07 AM
> To: statalist@hsphsun2.harvard.edu
> 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/



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