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

st: RE: if "macro" == value {


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: if "macro" == value {
Date   Mon, 1 Sep 2003 17:33:47 +0100

Chris Rohlfs
 
> i am running that looks like:
> 
> foreach S in fa sp ts {
> 	if [the macro S] ~="ts" {
> 		-- extra commands --
> 	}
> }
> 
> that is, i'm performing a set of commands once for the "fa" 
> string, once
> for "sp", and once for "ts".  my problem: i can't figure 
> out how to refer
> to the macro `S' and have stata realize that i'm referring 
> to the macro
> `S' and not a variable named S or "fa", etc...
> 
> is there a way to write this so that i can test whether the 
> macro S is
> equal to a given string fa, sp, or ts ?
> 

foreach S in fa sp ts {
	if "`S'" ~= "ts" {
 		-- extra commands --
 	}
}

Also see [P] foreach; Stata Journal 2(2), 202-222 (2002) 

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

*
*   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–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index