Statalist The Stata Listserver


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

st: RE: RE: foreach


From   "White, Justin" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: foreach
Date   Fri, 27 Oct 2006 10:19:41 -0400

I missed the "in" as well.  

Try this: 
foreach x of varlist ......... {
	replace `x' = "1" if `x'=="si"
	replace `x' = "0" if `x'=="no"
	destring `x', replace
	}

Justin White

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Maarten Buis
Sent: Friday, October 27, 2006 10:11 AM
To: [email protected]
Subject: st: RE: foreach

Ooops should be: foreach x of varlist p03a01 p03a01a-p03a01m {
note the of instead of in

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

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

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

-----Original Message-----
From: Maarten Buis 
Sent: vrijdag 27 oktober 2006 16:08
To: '[email protected]'
Subject: RE: foreach


foreach x in varlist p03a01 p03a01a-p03a01m {
     encode `x', gen(`x'2)      
}

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

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

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

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Ms. Marilyn
Ibarra
Sent: vrijdag 27 oktober 2006 16:02
To: [email protected]
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/


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