Callum Matthews
Callum Matthews

Reputation: 1

Reordering groups within a categorical variable

I'm struggling to reorder the categories in an income group variable.

It is currently in alphabetical order but I wish to change it to be permanently in order of amount (so moving £100 000 and greater to the bottom)

        Income Group |      Freq.     Percent        Cum.

       Under £20 000 |         11        9.73        9.73
£100 000 and greater |          7        6.19       15.93
   £20 000 to 29 999 |         18       15.93       31.86
   £30 000 to 49 999 |         38       33.63       65.49
   £50 000 to 74 999 |         27       23.89       89.38
   £75 000 to 99 999 |         12       10.62      100.00

Upvotes: 0

Views: 1111

Answers (1)

user9367317
user9367317

Reputation:

Create a new variable and assign each of the categories a number. For example,

gen     order = 1 if income=="Under £20 000"
replace order = 2 if income=="£20 000 to 29 999"
...
replace order = 6 if income=="£100 000 and greater"
sort order
drop order

If the income variable is numeric, rather than string, sub in the numeric values above.

Upvotes: 1

Related Questions