EconPapers    
Economics at your fingertips  
 

APPLYVARLABELS: Stata module to apply variable labels to the data in memory from a two-column (Variable, Label) crosswalk

Eric Booth

Statistical Software Components from Boston College Department of Economics

Abstract: Label the variables in memory from an Excel workbook or a delimited file that lists each variable name beside the label it should carry. Solves the Statalist problem (thread 1768839) where a levelsof/tokenize loop puts the wrong label on the wrong variable because levelsof sorts the labels alphabetically. applyvarlabels reads the crosswalk in row order and matches every label to its variable BY NAME, never by position. It writes a capture-guarded relabel do-file (a variable named in the crosswalk but absent from the data is skipped, not an error), runs it to apply the labels, and prints an inventory of what did not line up: crosswalk rows with no such variable, and variables in memory with no crosswalk row. The data in memory are never sorted, dropped, or reordered - the crosswalk is read in its own frame, so nothing changes but the variable labels themselves. The generated do-file is a keepable, rerunnable artifact (see dofile()). Reads .xlsx/.xls and .csv/.tsv/.txt; nocase matches names ignoring case; norun writes the relabel do-file without applying it.

Language: Stata
Requires: Stata version 16.0
Keywords: variable labels; codebook; data management; Excel (search for similar items in EconPapers)
Date: 2026-07-30
Note: This module should be installed from within Stata by typing "ssc install applyvarlabels". The module is made available under terms of the MIT license (https://opensource.org/licenses/MIT).
References: Add references at CitEc
Citations:

Downloads: (external link)
http://fmwww.bc.edu/repec/bocode/a/applyvarlabels.ado program code (text/plain)
http://fmwww.bc.edu/repec/bocode/a/applyvarlabels.sthlp help file (text/plain)
http://fmwww.bc.edu/repec/bocode/e/example_applyvarlabels.do example do-file (text/plain)
http://fmwww.bc.edu/repec/bocode/e/example_varlabels.xlsx example dataset (application/octet-stream)
http://fmwww.bc.edu/repec/bocode/m/make_example_varlabels.py Python helper script (text/plain)

Related works:
This item may be available elsewhere in EconPapers: Search for items with the same title.

Export reference: BibTeX RIS (EndNote, ProCite, RefMan) HTML/Text

Persistent link: https://EconPapers.repec.org/RePEc:boc:bocode:s459844

Ordering information: This software item can be ordered from
http://repec.org/docs/ssc.php

Access Statistics for this software item

More software in Statistical Software Components from Boston College Department of Economics Boston College, 140 Commonwealth Avenue, Chestnut Hill MA 02467 USA. Contact information at EDIRC.
Bibliographic data for series maintained by Christopher F Baum ().

 
Page updated 2026-08-14
Handle: RePEc:boc:bocode:s459844