Labeling variables

Variable label

Variable label helps us to know what the variable is about. This label will also conviently shows up as axis name if we were to draw a graph,

describe happiness

              storage   display    value
variable name   type    format     label      variable label
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
happiness       float   %9.0g                 

We can create labels to describe what the variable is measuring using label variable var_name.

label variable happiness "Feelings of happiness"
describe happiness


              storage   display    value
variable name   type    format     label      variable label
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
happiness       float   %9.0g                 Feelings of happiness

Value label

For categorical variables, we can create labels to show what does each level of the variable represents. This is helpful when we do a frequency table or fraw a graph.

To define the labels, we first use the command label define label_name to create a new label and give it a name. Then we specify the numerical value representing the category/level, then specify the label using a character string enclosed in " " double quotes.

Lastly, we need to apply the label we have created (happiness_label) to the corresponding variable (happiness).

// first define the label
label define happiness_label 1 "Very Happy" 2 "Rather Happy" 3 "Not very happy" 4 "Not at all happy"

// then apply the label to the variable
label values happiness happiness_label

tab happiness



     Feelings of |
       happiness |      Freq.     Percent        Cum.
-----------------+-----------------------------------
              -5 |          6        0.01        0.01
              -2 |        238        0.27        0.27
              -1 |        514        0.57        0.85
      Very Happy |     29,256       32.66       33.51
    Rather Happy |     45,786       51.12       84.63
  Not very happy |     11,214       12.52       97.15
Not at all happy |      2,551        2.85      100.00
-----------------+-----------------------------------
           Total |     89,565      100.00