Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Trouble with quotes in defining macro


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Trouble with quotes in defining macro
Date   Wed, 11 Nov 2009 17:12:51 -0000

I guess that's the price you pay for the dual role of double quotes, as
delimiters and as literal characters. 

Nick 
n.j.cox@durham.ac.uk 

Miranda Kim

Have got it to work after "playing around", though it's very messy and 
there is likely to be a much neater way...
Foreach var of varlist var1 var2 var3 {
    loc varlab `""`:var l `var''""'
    loc varlabs `"`varlabs'`varlab'"'
}

Miranda Kim wrote:
> I have the following problem:
>
> Within a loop I want to define a macro as follows:
>
> Foreach var of varlist var1 var2 var3 {
> local varlabs `varlabs' "`:var l `var''"
> }
>
> I want the macro varlabs to contain the following string ""lab1" 
> "lab2" "lab3"", where lab1 is the label for var1 etc.
> But I'm having problems with the quotes.
> I then want to use this local as an argument in another command and 
> that is why I wish it in this format with quotes around each label.
> I am using stata 10.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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