Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Help with - foreach - loop


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: Help with - foreach - loop
Date   Wed, 21 Mar 2007 07:58:29 -0400

You may need quotes
if "`x'"=="`a'" {

Michael Blasnik

----- Original Message ----- From: "Doogar, Rajib" <[email protected]>
To: <[email protected]>
Sent: Tuesday, March 20, 2007 6:23 PM
Subject: st: Help with - foreach - loop



Dear List,

I am trying to write a 'foreach x of varlist ...' loop in which I want
to use different data sets depending on which variable in varlist is
being processed.  When run, the following program correctly outputs
"Line 1" but fails to load tempa.dta and I cannot figure out why.  Any
tips will be most helpful.  Thanks.

foreach x of varlist a b c {
 if `x'==a {
   use tempa, clear
           }
 if `x'!=a {
   use tempb, clear
           }
 qui: do stuff
 di "Line 1"
<snip>
*
*   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