Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I am doing a study with 3 different types of fruit and I want to make a regression depending on the type that tries to predict the amount sold. I know that I could make 2 dummy variables: orange (V1:1,V2:0), pear (1,1), apple (0,1), for example. Is it also acceptable to make orange (V1:1) pear (2) and apple (3) for one variable? I have a large number of categories in my dataset, and I don't want to have to make a large number of dummy variables: I would rather just number them. Again, this is just going to be used for predictive purposes, not to try to detect the significance of the effect of the fruit type on the amount sold.

share|cite|improve this question
It is always better to use the conventional way of representing dummy variables. In my opinion for predictive purposes if you use 1, 2, 3 you will get into real trouble , because in that case things will get quiet messy. – SA-255525 Jul 19 '14 at 15:21
up vote 1 down vote accepted

The two ways you propose are not equivalent in an OLS regression. You should stick to the version where every fruit has a dummy. A generic OLS model is of the form $$y_i=\alpha+\beta_1 orange_i+\beta_2 apple_i+X\gamma+\epsilon_i.$$ So you need 2 dummies $orange,apple$, and if both are zero the constant $\alpha$ is the unconditional mean of pears. in general, you need $n-1$ dummy variables for $n$ categories.

If, instead, you estimate something like $$y_i=\alpha+\beta fruit_i+X\gamma+\epsilon_i,$$ with $$fruit=\begin{cases} 1 & \text{ if apple} \\ 2 & \text{ if orange} \\ 3 & \text{ if pear} \\ \end{cases}$$ then you implicitly assume the effect of changing from apple to orange is the same as switching from orange to pear, which doesn't make sense. One just doesn't represent categorical variables as continuous variables like this. Also, because your goal is prediction, the forecast based on the latter regression will usually be worse, because you use fewer variables/coefficients to predict and pool the categories you have in a linear form.

If you are concerned that the amount of variables becomes too big: some software packages like stata allow you to "batch-generate" dummy variables, so it doesn't take long to include all.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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