Statalist The Stata Listserver

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

st: RE: foreach

From   "White, Justin" <>
To   <>
Subject   st: RE: foreach
Date   Fri, 27 Oct 2006 10:07:37 -0400

Sorry, I forgot something:

This sounds to me that Stata is having a hard time recognizing your

Try listing each variable rather than using < p03a01a-p03a01m >.

Also, why generate y?

Why would you not use this:

foreach x in varlist ......... {
	replace `x' = "1" if `x'=="si"
	replace `x' = "0" if `x'=="no"
	destring `x', replace

Justin White

-----Original Message-----
[] On Behalf Of Ms. Marilyn
Sent: Friday, October 27, 2006 10:02 AM
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,
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index