Value labels

 

Value labels: words in place of numbers.

Value labels give more description than the integer values of a variable and can make it more user-friendly.

Stata does not allow value labels to be associated to a range of values (eg. 1-10 "low" 11-20 "med" 21-30 "high"). It is possible to get the same results by defining the same value label one-by-one to all integer values in the range. The foreach command may come to your rescue if the range is long. In this case, though, it would make more sense to create a recoded variable with 3 values (1="low", 2="med", 3="high").

Stata does not allow value labels to be associated with non-integer data (e.g., 1.5 "low" 2.1 "med" 3.3 "high") or with character strings (e.g., "Yes" "No").

Examples of the label command are shown below in a do-file.


clear
use "q:\utilities\statatut\examfac2.dta"
keep facid q102_1-q102_5

* Confirm that the variables are numeric (in this case "byte"). 
* Value labels named "title" are associated with the variables. 

describe

* Many commands, like browse, show the labels rather than the values. 
 
browse

* To see the values, use the "no label" option. 

browse, nolabel

* List all value labels stored in examfac2.dta. 

label dir

* Show what the value label title is. 

label list title

* These numbers are the actual data that STATA stores for each variable. 
* Notice that there is no value label for responses of 99.  Stata prints
*   the actual data for un-formatted responses. 

* Remove the value label title.  

label drop title
browse

* Re-create the title value label. 

#delimit ;
 label define title 
            1 "Doctor"
            2 "AssistMedOff"
            3 "ClinOff"
            4 "AssistClinOff"
            5 "NurseOff"
            6 "Nurse/Midwife";

* Add more to the title value label.; 

label define title
            7 "PH NurseB"
            8 "MCH Aide"
            9 "NurseAssist"
           10 "Other"
           11 "Dr. Doolittle", add;
#delimit cr

* Change the title value label. 

label define title 11 "", modify

* Re-assign the title value label to each q102_* variable. 
 
foreach v of varlist q102* {
   label val `v' title
}
browse

Questions:

1. How many characters long can a value label be? Answer.


2. Can I see both the values and the value labels at the same time? Answer.


3. Can value labels have the same name as the variable? Answer.

 


Answers:

 

1. The maximum length for a value label is 32,000 characters. See help limits for this and almost all other limits in Stata.

Back to question 

 


 

2. The label list command in the above example gives a kind of codebook for the values and labels. Otherwise, most commands give you either the value or the label but not both. One exception is the fre command, written by Ben Jann and available on CPC computers or by download from the SSC archive: ssc install fre It works like tab but shows both values and value labels in the tabulation.

Back to question 

 


 

 

3. Yes. For example, you could have a value label gender assigned to the variable gender

.

Back to question 

 


Review again?

 

Another topic?


Wink Plone Theme by Quintagroup © 2013.

Personal tools
This is themeComment for Wink theme