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

st: Problem with foreach loops


From   Ian Watson <i.watson@econ.usyd.edu.au>
To   statalist <statalist@hsphsun2.harvard.edu>
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: i.watson@econ.usyd.edu.au
  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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index