help for vallabsave, vallabload and vallabtran(Roger Newson)

Save and load value labels and transfer them between frames

vallabsave [ namelist ] using filename [, replace dslabel(string) ]

vallabload using filename [, replace ]

vallabtran [ namelist ] [, from(frame_name) to(frame_name) replace ]

where namelist is a list of names, assumed to belong to value labels.

Description

The vallabsave package contains 3 modules, vallabsave, vallabload and vallabtran.
vallabsave saves a list of value labels (defaulting to all value labels in the current dataset)
to a label-only Stata dataset in a disk file, containing no observations and no variables.
vallabload uploads labels from a label-only Stata dataset in a disk file
to the Stata dataset currently in memory.
vallabtran transfers a list of value labels
from one frame to another.
Label-only Stata datasets are a sensible way of storing value labels in a disk file,
if the labels may have text values that cannot be enclosed in compound quotes.
Such labels cannot be stored using label save,
or generated using label define,
but they may be generated using encode,
or using the SSC packages sencode and vallabdef.

Options for vallabsave

replace specifies that any existing file with the same name as the using file
will be overwritten.

dslabel(string) specifies a dataset label
for the newly created label-only dataset.

Options for vallabload

replace specifies that,
if any existing value labels of the same names exist in the current dataset,
then they will be replaced.
If replace is not specified,
then any existing value labels of the same names will only be modified,
so any values already labelled will retain the old labels if these are not modified.

Options for vallabtran

from(frame_name) specifies the frame from whch the value labels will be copied.
If absent, then the current frame is assumed.
If the namelist is absent,
then it is set to the list of all value labels present in the from() frame.

to(frame_name) specifies the frame to whch the value labels will be copied.
If absent, then the current frame is assumed.
If to() is specified and no frame of the specified name exists,
then a new frame of the specified name will be created,
to contain only value labels and no variables.

replace specifies that,
if any existing value labels of the same names exist in the frame specified by the to() option,
then they will be replaced.
If replace is not specified,
then any existing value labels of the same names will only be modified,
so any values already labelled will retain the old labels if these are not modified.

Examples

The following example demonstrates the creation of a value label reprec,
which is then saved to a label-only dataset myvallabs.dta using vallabsave.
The value label is then added to the auto data using vallabload,
and then assigned to the variable rep78.

Create the value label:

. clear

. label define reprec 1 "One" 2 "Two" 3 "Three" 4 "Four" 5 "Five"

. label dir

. label list

Save the value label in a label-only dataset:

. vallabsave reprec using myvallabs.dta, replace

Load the value labels into the auto dataset:

. sysuse auto, clear

. vallabload using myvallabs.dta

. label dir

. label list

. label value rep78 reprec

. tab rep78, miss

The following example demonstrates an alternative way of creating the value label,
using the SSC command vallabdef in a frame named vlframe,
inputting the auto data into another frame,
and using vallabtran to transfer the new label to be assigned to rep78:

Create the value label:

. frame create vlframe

. frame change vlframe

. input str32 labelname codeid str32 labeltext

. 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)

. vallabdef labelname codeid labeltext

. label list

. frame change default

Input auto data and assign label:

. sysuse auto, clear

. vallabtran reprec, from(vlframe) replace

. label list reprec

. label value rep78 reprec

. tab rep78, miss

Author

Roger Newson, Imperial College London, UK.

Email: r.newson@imperial.ac.uk

Also see

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

On-line: help for label, save, append, encode

help for sencode, vallabdef if installed