Statalist The Stata Listserver


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

st: Help with - foreach - loop


From   "Doogar, Rajib" <[email protected]>
To   <[email protected]>
Subject   st: Help with - foreach - loop
Date   Tue, 20 Mar 2007 17:23:19 -0500

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"
  if `x'==a {
    use tempa, clear
            }
  if `x'!=a {
    use tempb, clear
            }
  qui: do stuff2
  di "Line 2"
}

r.

Rajib Doogar,
Department of Accountancy,
The University of Illinois at Urbana-Champaign
1206 S. Sixth Street, Champaign, IL 61820
Ph: 217.244.8083, Fax: 217.244.0902
http://www.cba.uiuc.edu/doogar


*
*   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