Statalist The Stata Listserver


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

Re: st: Question on forvalues


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Question on forvalues
Date   Sun, 21 May 2006 08:33:09 +0100 (BST)

--- 宋时歌 <[email protected]> wrote:
> Can anybody kindly point out why the following code is not working?
> 
> 	forvalues n=1989 1991 1993 1997 2000 {
> 		replace waglevl_f`n' = . if waglevl_f`n'<0
> 		replace waglevl_m`n' = . if waglevl_m`n'<0		
> 		}

Shige:
-forvalues- expects a range not a list. If you want to loop over a list
you should use -foreach-. See -help forvalues- and -help foreach- for
more information. Correct code would be:

local varlist waglevl_f1989 waglevl_f1991 waglevl_f1993 /*
           */ waglevl_f1997 waglevl_f2000 waglevl_m1989 /*
           */ waglevl_m1991 waglevl_m1993 waglevl_m1997 /*
           */ waglevl_m2000

foreach var of varlist `varlist' {
	replace waglevl_f`n' = . if waglevl_f`n'<0
	replace waglevl_m`n' = . if waglevl_m`n'<0		
}

HTH,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

Send instant messages to your online friends http://uk.messenger.yahoo.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