2
$\begingroup$

I'm trying to see if it's possible to recode a categorical variable into a continuous variable. The data would probably not permit it but what if I really needed to find the mean and SD? Is there anything else I can do?

$\endgroup$
5
  • 2
    $\begingroup$ No matter what transformation you used, every datum in the same category would end up w/ the same value in the transformed space. Why do you need means & SDs? Are your categories ordered? $\endgroup$ Commented Apr 5, 2015 at 3:44
  • 1
    $\begingroup$ Certainly it's possible; depending on what you're using to analyze your data it's as easy as changing your categories from categorical factors into numbers. But what would having the mean or SD do for you that having counts of individuals in each category would not? $\endgroup$ Commented Apr 5, 2015 at 4:43
  • 2
    $\begingroup$ What are the categories? Why do you need means and sds? What makes doing this after some arbitrary recoding meaningful in your problem? $\endgroup$
    – Glen_b
    Commented Apr 5, 2015 at 8:16
  • $\begingroup$ Thanks for all of the feedback, everyone. I need means and SD because my second reader for my dissertation wants them even though it doesn't make sense for most of the categorical variables I have in my analysis. She claims that my current tables have too much information and want to streamline them. For some of my categorical vars, they're ordinal so I can get away with weighting them 1,2,3, etc but with other vars like "employment" it won't say much if anything at all with their mean and SD. $\endgroup$
    – Alvin Lee
    Commented Apr 6, 2015 at 1:23
  • $\begingroup$ A few current categories: Employment (unemployed, employed, not in labor force); Citizenship status ( citizen, non-citizen, naturalized, born-citizen) $\endgroup$
    – Alvin Lee
    Commented Apr 6, 2015 at 1:25

2 Answers 2

4
$\begingroup$

The way I understood your question was that you were wondering if there was a way for you to take your categorical variable where each category represents a range of continuous values, and assign a value for each observation that falls within the range represented by the category.

Example:

Observation     Categorical (have)    "Recoded" continuous value (want)
1               "1: 15 to 19"             15
2               "1: 15 to 19"             18    
3               "2: 20 to 24"             20
4               "2: 20 to 24"             22
5               "3: 25 to 29"             26
6               "3: 25 to 29"             26
7               "3: 25 to 29"             25
...

If this is the case, you probably should not do it. Categorical variables, by nature, mask the observed value of the constructs you are trying to measure. If the categories represent a range of values, you know that the observed value is somewhere within that range, but you don't know if it's closer to the lower end, the higher end, or the middle of the range. Of course it is possible to do these things mathematically, for example, assign a "random" value or impute a value, but what would the mean and SD for these values mean in the "real world" sense? How useful is it to look at the mean and SD of values that were artificially constructed if we do not know the "true" underlying distribution of the values?

You may be tempted to randomly assign a value within each category based on the range of that category, but without knowing what the "true" distribution is within each range (category), it's hard to justify assigning a random value based on that category's limits. There are many continuous variables that do not follow a normal distribution (which is why we categorize them before entering them into models). Income, for example, is generally positively skewed:

IFLS4 HH expenditure among women who had a birth in the 5 years preceding interview

Supposing the survey instrument collected income based using pre-determined categories of income in increments of 250,000 Rupiahs, the frequency distribution of the same data shown above may look something like:

         Categorical HH |
  expenditure per adult |
             equivalent |      Freq.     Percent        Cum.
------------------------+-----------------------------------
           0 to 250,000 |        350        6.98        6.98
  250,000.01 to 500,000 |      1,692       33.75       40.73
  500,000.01 to 750,000 |      1,245       24.83       65.56
750,000.01 to 1,000,000 |        723       14.42       79.98
             >1,000,000 |      1,004       20.02      100.00
------------------------+-----------------------------------
                  Total |      5,014      100.00

The frequencies do not tell us anything about how income is distributed within each category. Furthermore, the categorisation does not tell us what the upper limit is for the last category (in fact, it's just under 10,000,000). We can overlay vertical lines at 250,000, ..., 1,000,000 to see what the actual distributions look like with each of the 5 income ranges:

Histogram with overlays

We can even produce histograms for each category:

First

Histogram first category

Second enter image description here

Third enter image description here

Fourth enter image description here

Fifth enter image description here

For the first and last categories, there are clear trends in distribution as income increases. You can see how it would be a bad idea to "convert" the first category into a continuous variable by randomly assigning value between 0 and 250,000 because it clearly shows that people were more likely to be on the higher end of the range than the lower end. Similarly for the last category, people were more likely to have monthly income closer to 1,000,000 instead of the higher end of the range, so we can't just assign a random number for those people either. The distributions look more "random" for the middle 3 categories (the bars are closer in height to one another, and no clear increasing/decreasing/bimodal trend).

Of course this is an extreme example meant to show the dangers of "converting" categorical variables into continuous without knowing the underlying true distribution of the values. Your ranges may well be smaller than what I have shown in this example, but in the end, the question remains on what the means and SDs of the constructed (imputed?) values truly mean.

If what you mean is something completely different (the categories don't represent numbers but subjective attributes, e.g. 1=Blue, 2=Yellow, 3=Green), then my responses above would not apply. If this is the case, you can of course take the mean, SD, etc., but as other posters have mentioned, the question remains on how the mean/SD/etc. would be interpreted and whether it is useful.

$\endgroup$
0
$\begingroup$

It's certainly possible. In fact some statistical software would calculate mean and variance for a categorical variable. In lots of softwares all you have to do is just change the type of variable to numerical. But you have to ask yourself why. Why would you want to do that? Is there any reason? Are you sure you know what you are doing?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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