Reputation: 27
Im trying to recode multiple values in a column, it should be very simple.
recode the values -9,-8,-7 to NA in variable "var"
the stata equivalent is recode var_name (-9=.)(-8=.)(-7=.)(-2=.)(-1=.)
Thanks
Upvotes: 0
Views: 115
Reputation: 33802
Assuming you have a data frame, mydata
, with the values in column var
, you could use ifelse()
to generate the new values. Here they are stored in column y
but you could alter column var
if desired.
mydata$y <- ifelse(mydata$var %in% c(-9, -8, -7, -2, -1), NA, mydata$var)
Upvotes: 1
Reputation: 5429
your.data$var[ your.data$var %in% c( -9, -8, -7,-2,-1 ) ] <- NA
Find the ones matching your numbers and insert NA there
Upvotes: 1