• Laura Whiting

The Label Command - Text Labels for Categorical/Ordinal Variables

The label command can be used to create and attach labels to whole datasets, individual variables, or individual integer values within variables. The text labels you attach to the dataset and individual variables can be a maximum of 80 characters. Value labels, which create individual labels for each value within a variable, can be up to 32,000 characters long. Within a value label, you can associate up to 65,536 different integers to different text labels.


This post is specifically about value labels.


Value labels are useful when you have a categorical, ordinal, or dummy variable where the integers mean different things. You can create a value label that stores the text definition of each integer value, and then attach that to the variable so those text definitions are displayed. As an example, in the Stata example dataset auto.dta (open in Stata with sysuse auto in the command pane), there is a variable called “foreign”. This variable has a value label attached to it, that labels the integer 0 as “Domestic” and 1 as “Foreign”. This label gives an understanding of the variable by giving the values meaning for the user.


How to Use:

Worked Example:

For this example I use the auto dataset. This dataset has an ordinal variable called "rep78", with the label “Repair Record 1978”. This variable records the repair record of cars on a five-point scale, where 1 is very poor and 5 is excellent. I want to create a value label for this variable, to make the five-point scale easier to interpret. I am going to call my value label “rep78lbl”. It is generally good practice to name your value label after the variable you are attaching it to. I have added “lbl” at the end to distinguish it as a label name. In the command pane I type the following:

As you can see from the list generated above, the labels are now shown instead of the numbers. Please note the label is there for the user’s information, it does not alter the underlying values. When Stata performs analysis it still uses the numeric values, so when you ask Stata to analyse using a variable with a value label make sure you know the real values.

16 views

© 2020 by Survey Design and Analysis Services. 

  • LinkedIn
  • Facebook
  • Twitter
  • YouTube