|
Size: 1760
Comment:
|
Size: 1539
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 1: | Line 1: |
| = Metadata = | = Stata Metadata = |
| Line 13: | Line 13: |
| == Variable Names == | == Variable Labels == |
| Line 15: | Line 15: |
| Variables are (re)named using the `rename` command. Since Stata 12, it offers some advanced features: | Variable labels are defined using the '''`label`''' command. |
| Line 18: | Line 18: |
| // 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 |
label variable foo "bar" |
| Line 28: | Line 21: |
| For older versions of Stata, try these: | Variable metadata including labels can be inspected and exported using the '''`describe`''' command. |
| Line 31: | Line 24: |
| renpfix v V renpfix new_ // TODO: how did older versions rename variable to lowercase? |
preserve describe, replace assert varlab=="bar" if name=="foo" restore |
| Line 40: | Line 34: |
| == Labels == | == Value Labels == |
| Line 42: | Line 36: |
| === Variable Labels === | Variable labels are defined using the '''`label`''' command. However, they must first be defined as a label and then linked to one or more variables. |
| Line 45: | Line 39: |
| label variable VAR "var" | label define baz 0 "No" 1 "Yes" label define baz 99 "Missing", modify label values foo baz |
| Line 48: | Line 44: |
| 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. | |
| Line 49: | Line 46: |
=== Value Labels === Value labels are defined separately from the actual dataset. |
Numeric values can be added to value labels using the '''`numlabel`''' command. |
| Line 55: | Line 49: |
| 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("#. ") |
numlabel baz, add mask("#. ") |
Stata 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 Labels
Variable labels are defined using the label command.
label variable foo "bar"
Variable metadata including labels can be inspected and exported using the describe command.
preserve describe, replace assert varlab=="bar" if name=="foo" restore
Value Labels
Variable labels are defined using the label command. However, they must first be defined as a label and then linked to one or more variables.
label define baz 0 "No" 1 "Yes" label define baz 99 "Missing", modify label values foo baz
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 baz, 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
