Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: RE: AW: AW: recoding a variable


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: RE: AW: AW: recoding a variable
Date   Thu, 18 Feb 2010 15:07:47 +0100

<> 

" Another way to do it"


Though this represents a different take on the problem, one which leads to a
mapping of missings in the var to newvar, while mine set newvar to zero in
these cases:


*************
clear
set obs 10000
 
gen var=runiform()

replace var=. in 5/8

gen byte newvar=var>.5 & !mi(var)

gen byte newvar2 = cond(missing(var), . , var > .5)

l in 1/10, noo

*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox
Gesendet: Donnerstag, 18. Februar 2010 15:03
An: statalist@hsphsun2.harvard.edu
Betreff: st: RE: AW: AW: recoding a variable

Another way to do it 

gen byte newvar = cond(missing(var), . , var > .5) 

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

Martin Weiss

As always with the "greater than" operator in Stata, special care should
be
taken with regard to missings. So my expanded advice for you would be to
explicitly account for them:

clear
set obs 10000
 
gen var=runiform()
su var

//introduce missings
replace var=. in 5/8
ins var

//explicity deal with missings
gen byte newvar=var>.5 & !mi(var)
ta newvar, mis

l in 1/10, noo

Martin Weiss

replace var=var>.5

Data Analytics Corp. (Walter R. Paczkowski, Ph.D.) 

I got some very good quick advice on a looping question I asked 
earlier.  I have another question.  Suppose I have a variable with 
values that range between 0 ands 1.  I simply want to recode this so 
that any value greater than 0.5 becomes a 1, and 0 otherwise.  How do I 
do this?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index