help labrec

Title

labrec -- Recode variables according to value label

Syntax

labrec # "label" [# "label" ...]
[, options]

variables(varlist) recode variables specified in varlist

abbrev recode if specified label is part of a value label

nomatch recode only if labels perfectly match

nochange keep original label

noreplace do not recode variables

tra change left single quote to typewriter apostrophe

Description

labrec recodes variables according to a user defined value label. The user is to
define a value label in the same way this would be done using label define
(except no labelname is specified). labrec will recode any variable specified in
varlist according to the defined value label, if the defined label/s match
the (value) label/s attached to the variable. The value label/s themselves are also
"recoded".

Options

Options

variables(varlist) specifies that only variables in varlist are to be
recoded. The default is _all.

abbrev changes value labels and recode variables if a value label contains the
specified label. This option can be used to abbreviate labels, but it is not
limited to abbreviations (see example).

nomatch changes value labels and recode variables only if the label/s perfectly
match. If specified, "Refusal" for example does not match "refusal". In default
setting capitalization does not matter. This option is ignored if abrevv is
specified.

nochange uses the original label to "recode" the value labels. By default the
user defined label is used (see example).

noreplace does not recode variables. If specified, only the value labels will be
"recoded", while the variables will remain unchanged. If you think about using this
option you might want to see labmm which modifies value labels, first. To
install type: . ssc install labmm

tra changes left single quotes that are used in value labels to typewriter
apostrophe (which is the same as the right single quote). Suppose the value label
"somelabel" associates value 99 with label "don`t know". Here the left single quote
(`) is used as an apostrophe. labrec will return error code r(132)
(too few quotes) for value label "somelabel", because no matching right single quote
is found. Specifying tra will change the single left quote in "don`t know" to a
typewriter apostrophe (').
Caution: the program will perform even slower if this option is specified, since
every single value label has to be checked. I recommend running the program first
without specifying tra. If there are any error messages you can run the program
a second time for the variable/s that produced the error/s, specifying tra and
the variables() option.

Examples

To see how labrec works consider a simple example:

. tab mar

Marital |
status | Freq. Percent Cum.
------------+-----------------------------------
not married | 3 25.00 25.00
married | 6 50.00 75.00
Refusal | 3 25.00 100.00
------------+-----------------------------------
Total | 12 100.00

. label list marlbl
marlbl:
0 not married
1 married
9 Refusal

. labrec .a "refusal" ,var(mar)
1 change(s) made

. tab mar

Marital |
status | Freq. Percent Cum.
------------+-----------------------------------
not married | 3 33.33 33.33
married | 6 66.67 100.00
------------+-----------------------------------
Total | 9 100.00

. label list marlbl
marlbl:
0 not married
1 married
.a refusal

The three missing observations are coded ".a". You will get the same result using
mvdecode and label define with the modify option.

Now consider a large(r) data set, in which the values associated with the answers
"don't know" and "refusal" differ across variables. The spelling of the labels also
vary.

. label list
tvlbl:
1 no time at all
2 less than 30 min
3 30 to 60 min
4 60 to 90min
5 90-180min
6 more than 180min
8 don't know
9 refused
marlbl:
0 not married
1 married
9 Refusal
pollbl:
-9 REFUSAL
-8 DON'T KNOW
1 very interested
2 quite interested
3 hardly interested
4 not at all interested
agelbl:
888 Don't know
999 Refusal

Of course it is still possible to work with the above mentioned commands, but it will
take a lot of typing. Using labrec instead, only one line will be needed:

. labrec .a "don't know" .b "refus" ,abbrev nochange

How to use the options

Note the use of abbrev and nochange above. In the former option the
abbreviation "refus" is used in order to match "refusal" as well as "refused". Without
the latter option, value ".b" would be labeled "refus". You might want to use these
two options together every time you are using abbreviations but abbrev is not
limited to this kind of usage. Suppose there are numeric prefixes assigned to the
value labels in the data by numlabel.

. label list marlbl
marlbl:
0 0. not married
1 1. married
9 9. Refusal

. labrec .b "refusal" ,var(mar)
0 change(s) made

There are no changes made, because "refusal" does not match "9. refusal". Specifying
the abbrev option will solve this problem.

. labrec .b "refusal" ,var(mar) abbrev
1 change(s) made

. label list marlbl
marlbl:
0 0. not married
1 1. married
.b refusal

Use this option carefully. Typing:

. labrec .b "r" ,var(mar) abbrev

will result in:

. label list marlbl
marlbl:
.b r

since "not married", "married" and "Refusal" all contain "r" (or "R" as capitalization
does not matter).

Using the nomatch option:

. labrec .a "don't know" .b "refusal" ,var(age) nomatch
0 change(s) made

results in 0 changes, because "don't know" does not match "Don't know" and "refusal"
does not match "Refusal".

Hint: To change numeric values to system missing values, type:

. labrec . "label"

This line will remove label and the associated numeric value form the value
labels and change the variable values accordingly.

Acknowledgments

The package labelsof written by Ben Jann is required in order to obtain the
value labels attached to each variable. To install this package type

. ssc install labelsof

The name labrec is in line with the commands in the labutil package
by Nicholas J. Cox. To install this package type

. ssc install labutil

Author

Daniel Klein, University of Bamberg, daniel1.klein@gmx.de

Also see

Online: label, recode, mvdecode

if installed: labelsof, labcd, labcopy, labdel,
lablog, labdtch, labmap, labnoeq, labvarch,
labvalch, labmask, labvalclone, labeldup,
labelrename