ARCHIVED: 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 this 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 data set, 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 with the Variables Manager in the GUI. From the menu, select .
If you have questions about using statistical and mathematical software at Indiana University, contact the UITS Research Applications and Deep Learning team.
This is document arrs in the Knowledge Base.
Last modified on 2023-05-09 14:41:57.