Encoding data with categorical variables