[英]How can I generate AGE categorical/binary variable?
I tried using the below code but it throws an error in Stata.我尝试使用以下代码,但它在 Stata 中引发错误。
gen agecat=.
replace agecat=1 if age<=20
replace agecat=2 if age==21-30
replace agecat=2 if age==31-40
replace agecat=2 if age>=64
Would this work?这行得通吗? If not, you must let us know what error you get.
如果没有,您必须让我们知道您遇到了什么错误。 It is difficult for us to help you if we do not know what error you get.
如果我们不知道您遇到什么错误,我们很难为您提供帮助。
gen agecat = 1
replace agecat = 2 if age > 20
replace agecat = 3 if age > 30
replace agecat = 4 if age >= 64
If the age
variable has missing values you probably want to add replace agecat = . if missing(age)
如果
age
变量缺少值,您可能想要添加replace agecat = . if missing(age)
replace agecat = . if missing(age)
. replace agecat = . if missing(age)
。 Otherwise all missing values would also be in the last category as numeric missing in Stata is treated as infinite (arbitrarily large), which is certainly larger than 64.否则所有缺失值也将在最后一个类别中,因为 Stata 中的数字缺失被视为无限(任意大),它肯定大于 64。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.