Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2023-06-08 01:06:45
Size: 994
Comment:
Revision 4 as of 2025-10-24 17:18:34
Size: 1405
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`label`''' command adds labels to datasets, variables, or values. '''`-label-`''' manipulates [[Stata/Metadata|metadata]].
Line 13: Line 13:


=== Datasets ===
To assign a label to a dataset, try:
Line 21: Line 19:


=== Variables ===
To assign a label to a variable, try:
Line 29: Line 25:


=== Values ===

Value labels are not stored in the dataset itself.

To create a new value label and then attach it to a variable, try:
Value labels are not stored in the dataset itself. To create a new value label and then attach it to a variable, try:
Line 43: Line 33:
To query the labels, try: To query these value labels, try:
Line 56: Line 46:
== Stored Results ==

`label dir` stores the names of all labels in `r(names)`.

`label list` stores the following details:

 * the number of values with labels, in `r(k)`
 * the lowest non-missing value with a label, in `r(min)`
 * the highest non-missing value with a label, in `r(max)`
 * whether or not (i.e. 1 or 0) labeled missing values (i.e. `.a`) have labels, in `r(hasemiss)`

----


Line 58: Line 63:
[[https://www.stata.com/manuals/dlabel.pdf|Stata manual for label]] [[https://www.stata.com/manuals/dlabel.pdf|Stata manual for -label-]]

Stata Label

-label- manipulates metadata.


Usage

To assign a label to a dataset, try:

label data "Raw dataset"

To assign a label to a variable, try:

label variable foo "foo: A variable"

Value labels are not stored in the dataset itself. To create a new value label and then attach it to a variable, try:

label define yesno 1 "Yes" 0 "No"
label copy yesno yesno2
label values foo yesno

To query these value labels, try:

label dir
label list yesno yesno2

By default, value 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.


Stored Results

label dir stores the names of all labels in r(names).

label list stores the following details:

  • the number of values with labels, in r(k)

  • the lowest non-missing value with a label, in r(min)

  • the highest non-missing value with a label, in r(max)

  • whether or not (i.e. 1 or 0) labeled missing values (i.e. .a) have labels, in r(hasemiss)


See also

Stata manual for -label-


CategoryRicottone

Stata/Label (last edited 2025-10-24 17:18:34 by DominicRicottone)