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

Re: st: foreach-loop


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: foreach-loop
Date   Mon, 10 Jan 2005 12:00:59 +0100

Hans J. Baumgartner wrote:
> Dear statalist,
>
> within a foreach-loop I would like to add loop-specific routines. I.e.:
>
> foreach x in one two {
> 	some fancy commands
> 	if `x’=="one" {
> 		do this
> 	}
> 	if `x’=="two" {
> 		do that
> 	}
> 	some other fancy commands
> }

If you want to check whether `x' contains the _string_ "one", you need to put 
quotes around `x': 

foreach x in one two {
 	some fancy commands
 	if "`x’"== "one" {
 		do this
 	}
 	if "`x’" == "two" {
 		do that
 	}
 	some other fancy commands
 }


-- 
[email protected]
+49 (030) 25491-361


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