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

st: RE: Replace for a group of variables


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Replace for a group of variables
Date   Tue, 18 Nov 2003 13:25:56 -0000

forval i = 1001/1014 { 
	replace svi`i' = . if inrange(svi`i', -90005,-90001) 
} 

or 

mvdecode svi1001-svi1014, mv(-90005/-90001) 

The first makes an assumption that only integers are 
observed. You can add 

& (svi`i' == floor(svi`i')) 

to ignore non-integers. 

The second makes an assumption that your variables
svi* are in order in memory. 

Nick 
n.j.cox@durham.ac.uk 

Enrico Pellizzoni
> 
> 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

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