Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: local command with blanks


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: local command with blanks
Date   Mon, 27 Dec 2010 11:57:46 -0500

At 10:59 AM 12/27/2010, Kamyar wrote:

How can I create a local variable when I have blanks. I would like to
have such a thing:
local year_criteria    " "year < 2000 & age == 1" "yea r< 2002  & age == 2" "
I would like to use it in foreach command:

foreach criteria in `year_criteria' {
...
}

For the record, that's a local macro, not a local variable.
Putting that aside, I believe that all you need is to enclose the value in compound quotes:

local year_criteria `""year < 2000 & age == 1" "year< 2002  & age == 2""'

To be totally secure (or maybe it is necessary --?), you may want compound quotes inside:

local year_criteria `"`"year < 2000 & age == 1"' `"year< 2002  & age == 2"'"'

(I presumed that the space in "yea r" was spurious.)

But it may be more appropriate to define indicator variables for these criteria; then put the variable names into a macro:
gen byte crit1 = year < 2000 & age == 1
gen byte crit2 = year < 2002 & age == 2
local year_criteria "crit1 crit2"
foreach criteria in `year_criteria' {
...
}
----
HTH
--David

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index