I always have to use the expression of greater than and not missing to define a variable, like gen x = 1 if age >= 50 & !missing(age).
Is there an easy way to simplify this expression using functions or packages?
Thank you!
g x = if age >= 50 & !mi(age)
gen byte age50 = inrange(age, 50, .) if !mi(age) gen byte age50 = age >= 50 if !mi(age)
gen byte age50 = inrange(age, 50, .) if !mi(age) gen byte age50 = age >= 50 if !mi(age)
gen x = . replace x = 1 if age > 18 & age < 30 & mi(x) replace x = 2 if age >= 30 & age < 40 & mi(x) ....
gen x = . replace x = 1 if age > 18 & age < 30 & mi(x) replace x = 2 if age >= 30 & age < 40 & mi(x) ....
gen wanted = cond(missing(age), ., cond(age > 65, 4, cond(age > 40, 3, cond(age > 20, 2, 1))))
gen wanted = cond(missing(age), ., cond(age > 65, 4, cond(age > 40, 3, cond(age > 20, 2, 1))))
Comment