Differences between revisions 2 and 16 (spanning 14 versions)
Revision 2 as of 2020-03-03 19:23:38
Size: 911
Comment:
Revision 16 as of 2025-10-24 15:58:53
Size: 942
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Metadata = = Stata Metadata =
Line 3: Line 3:
Data about data. Stata exposes a rich API for querying internal '''metadata'''.

<<TableOfContents>>
Line 8: Line 10:
== Labeling ==
Line 10: Line 11:
=== Variable Labels === == Labels ==

Variable and value labels are primarily manipulated by the [[Stata/Label|`-label-`]] command.
Line 13: Line 16:
label variable VAR "var" . label variable foo "yes or no?"

. label define yesno 1 "Yes" 0 "No"

. label values foo yesno

. label list yesno
yesno:
           0 No
           1 Yes
Line 16: Line 28:


=== Value Labels ===

Value labels are defined separately from the actual dataset.
Numeric values can be quickly prepended to value labels using the '''`-numlabel-`''' command.
Line 23: Line 31:
label define LABEL 0 "No" 1 "Yes"
label define LABEL 99 "Missing", modify
label values VAR LABEL
numlabel foo, add mask("#. ")
Line 28: Line 34:
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.
To access or store the text of a variable label, try:
Line 33: Line 37:
numlabel LABEL, add mask("#. ") local varlab_foo: variable label foo
}}}

To manipulate value labels, try:

{{{
local vallab_foo: value label foo
local vallab_foo_1: label `vallab_foo' 1, strict
Line 40: Line 51:
== Quick Tips ==

Stata has a number of interactive tools for examining metadata.
== Descriptives ==
Line 45: Line 54:
di _N // number of cases
di c(k) // number of variables
display _N // number of cases
display c(k) // number of variables

Stata Metadata

Stata exposes a rich API for querying internal metadata.


Labels

Variable and value labels are primarily manipulated by the `-label-` command.

. label variable foo "yes or no?"

. label define yesno 1 "Yes" 0 "No"

. label values foo yesno

. label list yesno
yesno:
           0 No
           1 Yes

Numeric values can be quickly prepended to value labels using the -numlabel- command.

numlabel foo, add mask("#. ")

To access or store the text of a variable label, try:

local varlab_foo: variable label foo

To manipulate value labels, try:

local vallab_foo: value label foo
local vallab_foo_1: label `vallab_foo' 1, strict


Descriptives

display _N    // number of cases
display c(k)  // number of variables


CategoryRicottone

Stata/Metadata (last edited 2025-10-24 15:58:53 by DominicRicottone)