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

Re: st: Replace for a group of variables


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: Replace for a group of variables
Date   Tue, 18 Nov 2003 14:50:00 +0100

Enrico Pellizzoni wrote:
> Dear Stata listers,
>
> Does anyone know how it is possible to execute this set of instruction in a
> synthetic way?

> replace svi1001=. if svi1001==-90001 | svi1001==-90002 | svi1001==-90003 |
> svi1001==-90004 | svi1001==-90005 
> replace svi1002=. if svi1002==-90001 |
> svi1002==-90002 | svi1002==-90003 | svi1002==-90004 | svi1002==-90005
> replace svi1003=. if svi1003==-90001 | svi1003==-90002 | svi1003==-90003 |
> svi1003==-90004 | svi1003==-90005 replace svi1004=. if svi1004==-90001 |
> svi1004==-90002 | svi1004==-90003 | svi1004==-90004 | svi1004==-90005
> replace svi1005=. if svi1005==-90001 | svi1005==-90002 | svi1005==-90003 |
> svi1005==-90004 | svi1005==-90005 replace svi1006=. if svi1006==-90001 |
> svi1006==-90002 | svi1006==-90003 | svi1006==-90004 | svi1006==-90005
> replace svi1007=. if svi1007==-90001 | svi1007==-90002 | svi1007==-90003 |
> svi1007==-90004 | svi1007==-90005 replace svi1008=. if svi1008==-90001 |
> svi1008==-90002 | svi1008==-90003 | svi1008==-90004 | svi1008==-90005
> replace svi1009=. if svi1009==-90001 | svi1009==-90002 | svi1009==-90003 |
> svi1009==-90004 | svi1009==-90005 replace svi1010=. if svi1010==-90001 |
> svi1010==-90002 | svi1010==-90003 | svi1010==-90004 | svi1010==-90005
> replace svi1011=. if svi1011==-90001 | svi1011==-90002 | svi1011==-90003 |
> svi1011==-90004 | svi1011==-90005 replace svi1012=. if svi1012==-90001 |
> svi1012==-90002 | svi1012==-90003 | svi1012==-90004 | svi1012==-90005
> replace svi1013=. if svi1013==-90001 | svi1013==-90002 | svi1013==-90003 |
> svi1013==-90004 | svi1013==-90005 replace svi1014=. if svi1014==-90001 |
> svi1014==-90002 | svi1014==-90003 | svi1014==-90004 | svi1014==-90005

There are several ways. Here are just 3 ideas

1)

. recode svi1001-svi1012 (90001/90005 = .)

2)

. mvdecode svi1001-svi1012, mv(90001/90005)

3)

. foreach var of varlist svi1001-svi1012 {
.	replace `var' = . if inlist(svi1001,90001,90002,90003,90004,90005)
.}



-- 
[email protected]


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