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

st: Problem with foreach loops


From   Ian Watson <[email protected]>
To   statalist <[email protected]>
Subject   st: Problem with foreach loops
Date   Mon, 7 Jun 2004 15:36:49 +1000

Dear statalist,

  Can anyone spot the mistake with the following snippet of code.

  It actually works fine, and recodes and labels the variable
  in the way I wish, but in exiting (?) the loops it runs into problems.

  Any advice would be most appreciated.
  
begin snippet==================
  
foreach x in ajbmspay ajbmssec ajbmswrk ajbmshrs ajbmsflx ajbmsall {
.      foreach y in pay security work hours flexibility overall{
.           recode `x'(-4 -3 -1=.), gen(a_`y')
.           la var a_`y' "Satisfaction with `y'"
.      }
}
(5475 differences between ajbmspay and a_pay)
(5475 differences between ajbmspay and a_security)
(5475 differences between ajbmspay and a_work)
(5475 differences between ajbmspay and a_hours)
(5475 differences between ajbmspay and a_flexibility)
(5475 differences between ajbmspay and a_overall)
a_pay already defined
r(110);

end snippet=========================

-- 
Kind regards,
 Ian                          

=================================
Ian Watson
Senior Researcher
acirrt
University of Sydney
NSW 2006
Australia

Phone: 02 9351 5622
  Fax: 02 9351 5615

Email: [email protected]
  Web: www.acirrt.com
================================

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