Reputation: 11
I want to count the proportion of a variable, but the warning "factor variables may not contain negative values" always come up. After I check the label list, it contains as below:
label list w38_E1a
:
w38_E1a:
-99 Refused
-98 Don't know
1 Yes
2 No
How do I remove this -99 and -98 data?
Thank you.
Upvotes: 1
Views: 1824
Reputation: 1
I could not find a way to respond to https://stackoverflow.com/users/15742435/jesse-kaczmarski or https://stackoverflow.com/users/15819003/bing and because I have not "earned" enough reputation I can't comment on their answers directly. However, one should note that their advice can work out in a wrong way:
Upvotes: 0
Reputation: 1
It seems that -99 and -98 are intended to code missing values, thus no outlier here. If this is the case, you should recode the values -99 and -98 of variables using the label w38_E1a to missing. To find the variables whose values are labeled with a specific value label you can use -findname- from SSC.
cap which findname
if _rc ssc install findname // install -findname if necessary
findname, vallabelname(w38_E1a)
foreach v of varlist `r(varlist)' {
recode `v' (-99 = .a ) (-98 = .b)
}
label def w38_E1a .a "Refused" .b "Don't know" -99 "" -98 "", modify
Upvotes: 0
Reputation:
Assuming that the data is coded as numeric type, then I would simply recode them to be positive because if they are categorical it shouldn't matter their sign,
recode w38_E1a (-99 = 99) (-98 = 98)
Upvotes: 1