1
$\begingroup$

I have a data set where some columns have discrete values like $x_2=('cat','dog','penguin')$, $x_3=( 'high', 'low')$ etc... how do I handle these values before to run a regression?

Do I have to convert them into integers like $x_2=(0,1,2)$, $x_3=(0,1)$?

Do I have to add more columns $x_{cat}, x_{dog}, x_{penguin}, x_{high}, x_{low}$ and assign them a value 0 or 1 ?

$\endgroup$
  • $\begingroup$ Most modern software does this for you. It does something similar to what you outline in your last sentence for some meaning of similar. I would recommend letting your software do the heavy lifting here and if it does not offer this facility then choose a different software. $\endgroup$ – mdewey Nov 21 '16 at 11:57
  • $\begingroup$ Do you have any web links where I can get more info ? $\endgroup$ – ozw1z5rd Nov 21 '16 at 13:03
  • $\begingroup$ There are some hints in this Q&A stats.stackexchange.com/questions/239427/… which is for logistic regression but applies to linear and Poisson as well. $\endgroup$ – mdewey Nov 21 '16 at 13:50
  • $\begingroup$ @mdewey I think you could easily turn your two comments into an answer. Or someone else could, if you don't want to. $\endgroup$ – Peter Flom Aug 14 '18 at 12:36
2
$\begingroup$

Converted to an answer from my comments.

Most modern software does this for you. It does something similar to what you outline in your last sentence for some meaning of similar. I would recommend letting your software do the heavy lifting here and if it does not offer this facility then choose a different software. There are some hints in this Q&A Dummy variables for categories in logistic regression and odd ratio which is for logistic regression but applies to linear and Poisson as well.

Note that your option $x_2$ may work as long as you tell the software these are categories not numerical values. Internally the software will do something like you last suggestion ($x_{cat}$) and so on.

$\endgroup$
  • $\begingroup$ (+1) As a slight elaboration: Even if your software doesn't use the ideas or terminology of dummy (better: indicator) variables, a variable with numeric codes 0 and 1 should always be treated decently by most programs. The one you have to watch really carefully is (cat, dog, penguin) as -- unless you explain otherwise -- there is no rationale for treating 0, 1, 2 literally (which here means numerically). You need the software to translate that on the fly to two indicator variables. $\endgroup$ – Nick Cox Aug 14 '18 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.