Stata Labels: Variable Labels, Value Labels, and label define
Well-labeled data is self-documenting. Here's the complete guide to variable labels, value labels, encode, decode, and label management.
Your regression table is full of unreadable codes, and reviewers keep asking what categories 1, 2, and 3 actually mean.
You will build a label system that makes outputs interpretable without manual relabeling in every script.
All examples tested in Stata 18 SE. Compatible with Stata 15+.
Quick Answer
- Use `label variable` for descriptive column names.
- Define category mappings with `label define` once, then reuse with `label values`.
- Keep one central labeling do-file for project consistency.
- Use `modify` when updating existing label maps.
Turn Numeric Codes into Interpretable Outputs
Set variable labels and reusable value-label dictionaries
Labeling is a core reproducibility task. Good labels reduce interpretation mistakes and make exported tables immediately readable.
Define value labels centrally and apply them consistently to all variables that use the same coding frame.
If you are extending this pipeline, also review Export Regression Tables in Stata and Stata Macros: local and global explained.
1clear all2set obs 2003gen firm_id = ceil(_n/2)4gen year = 2015 + mod(_n,8)5gen sector = mod(firm_id,3) + 16gen treated = mod(firm_id,2)78label variable firm_id "Firm identifier"9label variable year "Calendar year"10label variable sector "Sector code"11label variable treated "Treatment status"1213label define sector_lbl 1 "Manufacturing" 2 "Services" 3 "Public"14label values sector sector_lbl1516label define tr_lbl 0 "Control" 1 "Treated"17label values treated tr_lbl1819tab sector20tab treated Sector code | Freq. Percent Cum.
------------------+-----------------------------------
Manufacturing | 67 33.50 33.50
Services | 67 33.50 67.00
Public | 66 33.00 100.00
------------------+-----------------------------------
Total | 200 100.00Modify existing labels and audit assignments
Projects evolve. Category definitions change and labels need updates. Use modify mode instead of recreating labels from scratch.
After updates, audit with `label list` and tabulations to confirm assignment consistency.
1clear all2set obs 2003gen firm_id = ceil(_n/2)4gen year = 2015 + mod(_n,8)5gen sector = mod(firm_id,3) + 16gen treated = mod(firm_id,2)78label variable firm_id "Firm identifier"9label variable year "Calendar year"10label variable sector "Sector code"11label variable treated "Treatment status"1213label define sector_lbl 1 "Manufacturing" 2 "Services" 3 "Public"14label values sector sector_lbl1516label define tr_lbl 0 "Control" 1 "Treated"17label values treated tr_lbl1819tab sector20tab treated2122* ---- Section-specific continuation ----23label define sector_lbl 2 "Business Services", modify24label list sector_lbl2526* Assign same dictionary to a new variable27gen sector_alt = sector28label values sector_alt sector_lbl2930tab sector_altsector_lbl:
1 Manufacturing
2 Business Services
3 PublicCommon Errors and Fixes
"label sector_lbl already defined"
You attempted to redefine an existing value label without using the modify option.
Inspect current mappings with `label list` and then apply `, modify` for updates.
label sector_lbl already defined r(110);
label define sector_lbl 2 "Business Services"label define sector_lbl 2 "Business Services", modify1label list sector_lbl2label define sector_lbl 2 "Business Services", modify3label list sector_lbl. label define sector_lbl 2 "Business Services", modify
Command Reference
label define / label values
Stata docs โCreates and attaches category dictionaries to numeric-coded variables.
modifyUpdates existing definitions without recreationlabel variableAdds descriptive labels to variableslabel listDisplays current dictionary mappingslabel dropRemoves unused dictionariesHow Sytra Handles This
Sytra can generate complete labeling dictionaries from plain-language metadata and apply them consistently across files.
A direct natural-language prompt for this exact workflow:
Create a complete labeling script for sector and treatment variables, including variable labels, value labels, and a safe modify step that updates sector code 2 text.Sytra catches these errors before you run.
Sytra can generate complete labeling dictionaries from plain-language metadata and apply them consistently across files.
Join the Waitlist โFAQ
What is the difference between variable labels and value labels?
Variable labels describe columns, while value labels map coded numeric values to readable category names.
How do I update a label definition without breaking code?
Use `label define name value "text", modify` so existing labeled variables keep references and only updated mappings change.
Can value labels be shared across variables?
Yes. One value label definition can be applied to multiple numeric variables with compatible coding schemes.
Related Guides
- Importing Data into Stata: Excel, CSV, Fixed-Width, SAS, and SPSS
- Stata String Functions: substr, strpos, regexm, and 30 More with Examples
- Finding and Removing Duplicates in Stata: duplicates tag, report, drop
- How to Structure a Stata Project: Directory Layout, Naming, and Automation
- Explore the data management pillar page
- Open the full data management guide index
- Browse all Stata & R guides on the blog index
- Browse all Stata pillars
We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.