See following codes may solve both problems.
use auto, clear
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"')
* please note single quates around double quates
local brands buicks datsuns vws
foreach brand1 of local brands {
local all `all' ``brand1''
}
* please note the two single quates in ``brand1'' not double quates
foreach brand of local brands {
list price if `all'
}
exit
There are other ways to solve the long line problem, such as using #delimit
use auto, clear
#del ;
local all1 make==`"Buick Century"' | make==`"Buick Electra"' |
make==`"Buick Opel"' |
make==`"Datsun 200"' | make==`"Datsun 210"' | make==`"VW Dasher"' |
make==`"VW Rabbit"' | make==`"VW Scirocco"' ;
#d cr
local brands buicks datsuns vws
foreach brand of local brands {
list price if `all1'
}
exit
Zhiqiang
Menzies School of Health Research
Darwin Australia
----- Original Message -----
From: "Finne H�kon" <[email protected]>
To: <[email protected]>
Sent: Thursday, June 27, 2002 8:09 AM
Subject: st: getting the quotes right
> Dear Statalisters,
>
> I need to generate a command that eventually has the following structure:
>
> list v1 if v2=="alpha" | v2=="beta" | v2=="gamma"
>
> except that it is much longer (so it wraps over several lines) and is
inside
> a loop, so it will be repeated with a different number of different
> conditional elements each time. So I try something like this (I write it
in
> the auto dataset terminology to facilitate testing):
>
> 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 {
> list price if `brand'
> }
>
> Of course this does not work. There are two issues (I think):
> 1) to make sure that
> foreach number of local one two three {
> makes the loop run three times and not eight or more
> 2) to get double quotes and compound double quotes in the right places.
>
> The diagnostic phase of this problem is made more difficult because with
> -display- the various quotes seem to be parsed differently from
with -list-
> .
>
> Please, someone?
>
> -- H�kon
> [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/
>
*
* 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/