Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: AW: AW: recoding a variable

From   "Nick Cox" <>
To   <>
Subject   st: RE: AW: AW: recoding a variable
Date   Thu, 18 Feb 2010 14:02:55 -0000

Another way to do it 

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


Martin Weiss

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

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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index