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

st: RE: Re: getting the quotes right


From   Finne Håkon <Hakon.Finne@sintef.no>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: Re: getting the quotes right
Date   Thu, 27 Jun 2002 19:56:37 +0200

Thank you, Zhiqiang.
Your code results in listing all 8 prices three times. But you gave me the
real clue with
        local all `all' ``brand1''
i.e., recursive macro substitution. The following code actually works as
intended:

    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 make price if ``brand''
      }
It turns out, in fact, that the compound double quotes (instead of regular
double quotes) around Buick Century etc. are not needed, because the code
does not add any other qoutes. But they make no harm.

-- Håkon
hakon.finne@sintef.no


> -----Original Message-----
> From: Zhiqiang Wang [mailto:wang@menzies.edu.au]
> Sent: 27. juni 2002 06:54
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Re: getting the quotes right
> 
> 
> 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" <Hakon.Finne@sintef.no>
> To: <statalist@hsphsun2.harvard.edu>
> 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
> > hakon.finne@sintef.no
> > *
> > *   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/
> 
*
*   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