Stata 15 help for cond()

[FN] Programming functions


cond(x,a,b[,c]) Description: a if x is true and nonmissing, b if x is false, and c if x is missing; a if c is not specified and x evaluates to missing

Note that expressions such as x>2 will never evaluate to missing.

cond(x>2,50,70) returns 50 if x > 2 (includes x > .) cond(x>2,50,70) returns 70 if x < 2

If you need a case for missing values in the above examples, try

cond(missing(x), ., cond(x>2,50,70)) returns . if x is missing, returns 50 if x > 2, and returns 70 if x < 2

If the first argument is a scalar that may contain a missing value or a variable containing missing values, the fourth argument has an effect.

cond(wage,1,0,.) returns 1 if wage is not zero and not missing cond(wage,1,0,.) returns 0 if wage is zero cond(wage,1,0,.) returns . if wage is missing

Caution: If the first argument to cond() is a logical expression, that is, cond(x>2,50,70,.), the fourth argument is never reached. Domain x: -8e+307 to 8e+307 or missing; 0 means false, otherwise interpreted as true Domain a: numbers and strings Domain b: numbers if a is a number; strings if a is a string Domain c: numbers if a is a number; strings if a is a string Range: a, b, and c

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