Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Stata, how do I add a value label to a numeric variable?

Adding a value label to a variable in Stata is a two-step process. The first step is to use the .label define command to create a mapping between numeric values and the words or phrases used to describe those values. The second step is to associate a specific mapping with a particular variable using the .label values command. With the two-step process, you can associate one particular mapping with multiple variables, making it unnecessary to manually specify the same labels for n variables n different times.

For example, suppose you have data on the purchasing habits of car buyers. The respondents were asked whether the car they were trading in was foreign or domestic. They were also asked about the origin of the car being purchased. Both variables were coded 0 for foreign and 1 for domestic. In the dataset the variables are named oldcar and newcar, respectively. To assign appropriate labels, you would use the following commands:

.label define carlabel 0 "Foreign" 1 "Domestic" .label values oldcar carlabel .label values newcar carlabel

The first command creates a mapping that associates the descriptive label "Foreign" with the number 0 and "Domestic" with the number 1. It also gives this mapping the name carlabel. The second command associates the mapping carlabel with the variable oldcar. The third command does the same for the variable newcar.

Note: You can also add value labels to variables in Stata 11 with the new Variables Manager in the GUI. From the Data menu, select Variables Manager.

This is document arrs in domain all.
Last modified on March 10, 2011.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.