Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: local command with blanks


From   David Kantor <kantor.d@att.net>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index