I am currently moving from Stata to R, trying to do on R what I did on Stata, starting from scratch. I imported raw data from Stata and had to dump my labels to avoid them overwriting the variable values, and I'm now trying to generate them back in R, as well as generating my dummy variables again from multilevel variables.
SO I did that:
newvar<-basevar
newvar<-mapvalues(newvar, c(1, 2, 3, 4, 5), c(1, 0, 0, 0, 0 ))
newvar <- factor(newvar,
levels = c(0,1),
labels = c("Bad", "Good"))
describe(newvar)
This worked perfectly, and I got what I expected, a normal describe result with frequency and proportions, correctly labelled.
Then I realized my 0/1 values had been overwritten with 1 instead of 0 and 2 instead of 1.
Is that a normal part of how labelling works in R? Is there a way to add labels while conserving the initial values of the variable?
I'm used to working with 0 and 1, for coding efficiency (and since Stata tends to interpret 1/2 as numerical which added extra steps to go back to dummy variables, but since I set the variable as factor in R, I should not have this kind of problem), and labels to get perfectly understandable results (tables and graphs).
Should I learn to work differently with R?