Skip to content

value labes Stata vs factors

2 messages · Rob Bakker, Peter Dalgaard

#
Rob Bakker wrote:
Factors can't be averaged. You can average a score based on a factor 
though, as in

mean(c(1,2)[Rgenmetvl$sex])

or

mean(as.numeric(Rgenmetvl$sex))

These do the same thing, but the former allows you more control of the 
scores asssigned. Notice that the values need to be in the order of 
levels(Rgenmetvl$sex).

Alternatively, use read.dta(...., convert.factors=FALSE) to get a 
version of data containing the original numeric values.