Stata 11 help for cond()
help cond()
-------------------------------------------------------------------------------
Title
[D] functions -- Functions
Programming function
cond(x,a,b,c) or cond(x,a,b)
Domain x: -8e+307 to 8e+307 and 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
Description: returns a if x is true and nonmissing, b if x is false,
and c if x is missing.
returns 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, i.e., cond(x>2,50,70,.), the fourth argument
is never reached.
Also see
Manual: [D] functions
Help: [D] functions, [D] functions (programming functions), [U] 11.1.3
if exp, [P] if
|