## Introduction

This article describes how to calculate an average value from categorical data in Displayr.

The traditional means for outputting categorical data is with percentages representing each category's share of the total sample. However, there are a range of cases where it is useful to calculate an average value based on the categories.

This requires that each category in the data be associated with a meaningful value, so that the average is also meaningful. In this post, we look at how to assign numeric values categories in Displayr so that averages can be calculated.

## Requirements

One or more categorical variables containing ranges. For example:

## Method

To recode values in Q:

- Right-click on the labels in a table and select
**Values**. - Enter appropriate values for each category in the Value column.
- Click
**OK**.

In some cases, each category will have predefined numerical values like scale questions. See the following satisfaction question which a researcher has coded with 5 for “Extremely satisfied”, 4 for “Satisfied”, and so on.

It is easy to average the results for this question. The closer the overall average is to 5, the higher the level of satisfaction. Using the average also allows for easy crosstab comparison of sub-groups. You can apply this approach for virtually any scale-type question.

### Showing averages on categorical tables

Once these settings have been confirmed, you can add the average statistic to the bottom of the table by

- Right-clicking on the table and choosing
**Statistics – Below > Average**.

### Changing the question type

If the only statistic you want to show on a table is the average, changing the Question Type into either a **Number** or **Number – Multi** format can be a more sensible and direct option. By default, Q will always output the average statistic on tables utilizing these question types. Changing the Question Type makes it much easier to create crosstabs when comparing results for multiple items.

To do so:

- Right-click on a table showing your question.
- Find the name of the question in the context menu.
- Select
**Restructure Data > Average (Number)**(or**Averages (Number – Multi)**when there is more than one variable)**.**

### Automated solutions

In addition to these practical solutions, Q’s **Online Library** includes automated solutions to apply these changes on a larger scale.

- From the toolbar, select
**Browse Online Library > Recode > Recode Variable(s) Using Code/Category Midpoints**

This feature automatically recodes variables according to numbers contained in their labels. To get a new value, Q will use a single number or numeric value from the label. In this example, Q has used the numbers from each label as values and has assigned any labels that don’t contain numbers, a value of NaN. This will exclude them from contributing to the computation of any numeric statistics like Average or Sum.

If the label contains a range of values the mid-point between the two values will be used.

- From the toolbar, select B
**rowse Online Libary > Create New Variables > Numeric Variable(s) from Code/Category Midpoints**

This feature completes the same process, automatically recoding variables according to the numbers contained in their labels, but it takes the extra step of generating new numeric variables with this data. It follows the same logic wherein Q will assign the same value as labels that contain a single number and a midpoint value for labels that contain a range of numbers. If no number is detected in the label Q will assign the value of NaN.

## See Also

How to Update Value Attributes by Cutting and Pasting

How to set Value Attributes for a Pick Any and Pick Any-Grid

How to Recode Missing Values in Q

## Comments

0 comments

Article is closed for comments.