help for vallabdef(Roger Newson)

Define value labels from label name, value and label variables

vallabdef namevar codevar labelvar [if] [in]

where namevar is the name of a string variable containing label names,
codevar is the name of a numeric variable containing values to be labelled,
and labelvar is the name of a string variable containing the corresponding labels.

Description

vallabdef inputs 3 variables in the current dataset,
assumed to contain the names, values and labels
for one or more value labels,
and defines (or extends) the named value labels.
The user can then save the value labels in a label-only dataset on disk,
with no observations and no variables,
which can then be appended to another dataset,
and used as a source of value labels to be allocated to variables.
vallabdef is very useful for defining value labels
which cannot be defined using label define,
because they cannot be surrounded by simple or compound quotes

to integer variables in another dataset.

Set-up:

. clear all

. input str32 labelname codeid str32 labeltext

. cartype 0 "`US made'"

. cartype 1 "`Non-US made'"

. reprec 1 "One"

. reprec 2 "Two"

. reprec 3 "Three"

. reprec 4 "Four"

. reprec 5 "Five"

. end

. compress

. sort labelname codeid

. describe, full

. list, abbr(32) sepby(labelname)

Create and list labels:

. label drop _all

. vallabdef labelname codeid labeltext

. label dir

. label list

Save label-only dataset:

. drop _all

. save autolabs.dta, orphans emptyok replace

Load auto data and assign labels from label-only dataset:

. sysuse auto, clear

. append using autolabs.dta

. lab val foreign cartype

. lab val rep78 reprec

. describe, full

. tab foreign, miss

. tab rep78, miss

Stored results

lablist saves the following in r():

Macros

r(names) list of generated or modified label names in alphanumeric order

Author

Roger Newson, Imperial College London, UK.

Email: r.newson@imperial.ac.uk

Also see

Manual: [D] label, [D] save, [D] append

On-line: help for label, save, append

help for vallabsave, vallabload if installed.