I have a variable 'fav_color' with categorical data. Is there a STATA command to convert them to factors so blue will instead be 0, green will be 1, red will be 2 and yellow will be 3 so a regression will be easier to interpret (the same for fav_food)?
fav_color fav_food
blue apples
green soup
red steak
yellow fish
no answer left blank
I tried these commands but STATA prints an error message:
encode fav_color, generate(f_color)
error: not possible with numeric variable
destring fav_color, generate(f_color)
f_color already numeric; no generate
This works but it changes fav_color variable to a string which I do not want.
decode fav_color, gen(f_color)
Thanks
fav_color fav_food
blue apples
green soup
red steak
yellow fish
no answer left blank
I tried these commands but STATA prints an error message:
encode fav_color, generate(f_color)
error: not possible with numeric variable
destring fav_color, generate(f_color)
f_color already numeric; no generate
This works but it changes fav_color variable to a string which I do not want.
decode fav_color, gen(f_color)
Thanks
Comment