label
Attaches readable text to a column, or to the codes inside it.
What we have
label variablefor a descriptionlabel defineandlabel valuesfor the words behind the codeslabel listto see what is defined- labels read from a
.dtaand labels made byencode
Coming later
label language, for more than one set of labels at a time
How you write it
label variable var "text" | label define name 1 "a" 2 "b" | label values var name
Square brackets mean optional. A vertical bar means choose one.
What it does
Two separate jobs that share a word.
label variable mpce "Monthly spend per person"gives the column a description, which then appears indescribeand on charts.label define sexlab 1 "Male" 2 "Female"followed bylabel values sex sexlabmakes the number 1 print as "Male" wherever it appears. The stored value is still 1, so arithmetic and models are unaffected — only the printing changes (value labels).
label list shows what you have defined.
Try it
Every example below was run after sysuse vira.sample02, clear.
. label variable mpce "Monthly spend"
The same thing in pandas and in R
R
# no R form for `label` yet -- see docs/r-equivalents.md
. label list
sector:
1 Rural
2 Urban
sex:
1 Male
2 Female
The same thing in pandas and in R
R
# no R form for `label` yet -- see docs/r-equivalents.md