Statalist The Stata Listserver


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

st: RE: foreach


From   "Riano, Juanita" <JRiano@imf.org>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: foreach
Date   Fri, 27 Oct 2006 10:14:45 -0400

Marilyn, 

I think the problem with the varlist is that you need to use "of"
instead of "in" :

Replace:
foreach var in varlist p03a01 p03a01a-p03a01m 

With:
foreach var of varlist p03a01 p03a01a-p03a01m 

Or alternatively use

foreach x in p03a01 p03a01a-p03a01m


Juanita

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ms. Marilyn
Ibarra
Sent: Friday, October 27, 2006 10:02 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: foreach

I have data that is coded as "si" or "no".  I need to change this to
numeric variables.  I tried the following but keep getting an error
message that says, "varlist not found". Can anyone tell me what I am
doing wrong?

Here is the code:

foreach x in varlist p03a01 p03a01a-p03a01m {
	gen y = (`x' == "si")
	replace y = 0 if (`x' =="no")
	drop `x'
	rename y `x'
	}

Thank you in advance,
Marilyn. 
*
*   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/

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