# Treating a variable as categorical or continuous

Suppose a variable $T$ (temperature) is coded as follows: $T = 1$ if temperature < 10, $T = 2$ if 10 < temperature < 40, and $T=3$ if temperature > 40. Is it better to treat $T$ as a categorical variable?

• Seems to me that your data is categorical now. I'm not sure if methods that work with censored data could buy you anything here. Do you know the actual range of the temperature? If it was, say 0-50, then T=2 is obviously a much larger bucket than the other two. – Wayne Mar 6 '12 at 20:06

## 4 Answers

@Wayne is right that you have already decided to categorize your variable, so in some sense the deck is loaded. However, I think it would be better to set your categorization aside and go with your original continuous variable. As it happens, I just discussed this issue in another question (and a slightly different context). See here (1/2 way down) for a list of reasons why it's better to leave continuous variables in their original form.

• Ah, yes: if you have access to the original data, use it. Depending on what you want to do, it may be useful to have your categorical T, to break the model into parts, but the real work will be done with the original data. – Wayne Mar 6 '12 at 20:22

I think the question maybe whether there is a way to treat the data "as is" as continuous, somehow.

It may be.

If you know the minimum and maximum temperatures, and if you can make some reasonable assumptions about the distribution, you can come up with "recreated" continuous data out of your ordinal factor.

For example, say your data is temperature in New York City in degrees centigrade on each day in the distant year for which exact data are not available. You will not be able to recreate the exact temperature, but you can "fake it" by using data from years where temperature is available.

Of course, this will be much noisier than the real data, and if you have nothing else to go on, it might not be worth it. But if this is the real example, you would have a guess as to temperature on the day before and the day after ....

Is this a good idea? I'm not sure. It probably depends on the exact situation.

I think this could be an interesting larger question.

It also depends on what inferences you wish to make. Using continuous data is useful if you wish to make predictions for values of $T$ not within your data set, as there exists a sensible connection between values of $T$ when measured on a continuous scale. Specifying your data as categorical limits such predictions.

If you want to encompass categorical data analysis, then you might want to treat continuous variables as categorical variables. For example, if you want to perform Mantel-Haenszel chi-square test, an appropriate categorization is needed.

In terms of categorization, you need to categorize them in a sensible way because we don't have too few records for T=1 and too many records for T=2, for instance.