Skip to main content
MedCalc
Mail a PDF copy of this page to:
(Your email address will not be added to a mailing list)
working
Show menu Show menu

How to reorder a categorical variable

Suppose you have the following categorical data, with 2-digit codes representing some European countries (DE: Germany, FR: France, NO: Norway, SE: Sweden, O: Other):

Reorder a categorical variable

You can create a frequency chart by completing the following dialog:

Reorder a categorical variable

This will result in the following graph:

Reorder a categorical variable

Now we want to:

  • Replace the 2-digit country codes with the full country names
  • Change the order of the countries so that the countries appear alphabetically with the Others bar at the utmost right.

We proceed as follows.

Click Edit variables list on the Tools menu to obtain the following dialog:

Reorder a categorical variable

You select the variable Country and click Properties. This will give the following dialog:

Reorder a categorical variable

In this dialog you can assign labels to the different categories and define their order.

Click Scan data to scan the data and to populate the list with existing values.

Reorder a categorical variable

Click in the cells in the Label column to change the codes into country names:

Reorder a categorical variable

Now select the category of which you want to change the order and click the Up button and Down button buttons to change the order.

Reorder a categorical variable

Proceed in the same way to bring France to the top of the list.

Reorder a categorical variable

Now return to the Frequencies bar chart dialog:

Reorder a categorical variable

The new graph looks like this:

Reorder a categorical variable