Metadata
Stata offers human-readable variable names, variable labels, variable printing formats, and value labels.
Stata stores variable labels and value labels in a separate database. Many built-in commands seamlessly pull in metadata from that database, but there are notable exceptions.
Variable Names
Variables are (re)named using the rename command. Since Stata 12, it offers some advanced features:
// rename all variables with a leading 'v' such that the 'v' is replaced with a 'V' rename v* V* // rename all variables with a leading 'new_' such that the prefix is stripped rename new_* * // rename all variables to a lowercase name rename *, lower
For older versions of Stata, try these:
renpfix v V renpfix new_ // TODO: how did older versions rename variable to lowercase?
Labels
Variable Labels
label variable VAR "var"
Value Labels
Value labels are defined separately from the actual dataset.
label define LABEL 0 "No" 1 "Yes" label define LABEL 99 "Missing", modify label values VAR LABEL
By default, labels cannot be overwritten. The add option allows new values to be inserted into an existing label. The replace option allows existing values to be overwritten in an existing label. The modify option combines both.
Numeric values can be added to value labels using the numlabel command.
numlabel LABEL, add mask("#. ")
Quick Tips
Stata has a number of interactive tools for examining metadata.
di _N // number of cases di c(k) // number of variables