Missing values pitfall with Boolean statements

Missing values pitfall with Boolean statements

by Mark Pletcher -
Number of replies: 0

This Forum post is referred to in Lab 3 - don't worry about it now, but it may come in handy later...

Stata treats missing values in numeric variables (".") as REALLY BIG numbers when evaluating Boolean logic statements. Say, for example, that age is missing in 4 people in your dataset. If you generate a new variable to indicate people older than 50, like this:

gen ageover50 = 0
replace ageover50 = 1 if age>50

Stata will evaluate the "if age>50" Boolean statement as "true" for observations where age = ".", and those 4 people with missing values will be coded as ageover50 = 1! 

There is a reason Stata does this, but I'm not sure what it is...just BEWARE, and always check your missing values. This is NOT a problem with the recode command structured like this:

gen ageover50 = age
recode ageover50 min/49=0 50/max=1

In this case, Stata will get it right and leave the missing values as missing.