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:
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.
Last modified on March 10, 2011.







