11 Labelling

11.1 Variables

Variable names are not always very human friendly. It is useful therefor to be able to attach a label to a variable, especially for use in output such as graphs.

Add the following line of code to your script

label variable sex "Gender"

now use the table command to view a table of frequencies of the sex variable. What has been the effect of your line of code?

11.2 Exercise

Create appropriate labels for the variables in your data set.

11.3 Values

When we record some categorical variables, we will often use a code to represent the different possible values. for example, we might code eyecolour as

Code Meaning
1 Brown
2 Blue
3 Grey
4 Green
5 Other

The use of numeric codes is very convenient in many circumstances, but it is not very human friendly. We would also like to put more meaningful labels for the values on output such as tables and graphs. To do this we create a label set and apply it to the variable values.

The label set is a list of codes and meanings create by a command like

label define eyecolourlabels 1 "Brown" 2 "Blue" 3 "Grey" 4 "Green" 5 "Other"

We then apply the labels to values of a variable eyecolour with a command like

label values eyecolour eyecolourlabels

11.4 Exercise

Create an appropriate label set for the variable sex in your data set and apply it to the values of sex. Use the list command to check the results. What do you see?