help renlabv

Title

renlabv -- Renames value labels to match the names of assigned variables

Syntax

renlabv [varlist] [, options]

options

nodrop do not drop original value labels

Description

As a wrapper of the SSC program elabel by Daniel Klein, renlabv renames
value labels to match the name(s) of the assigned variable(s). Hence, the program
will require that elabel is installed. After using renlabv without
specifying any variable the names of all value labels of the data set will be
equal to the names of the assigned variables. By default renlabv will
drop the original value labels. Note that value labels not assigned to variables
will not be renamed or dropped.

Stata allows to attach a value label to several variables; this may be regarded
as a feature (see the PDF documentation [D] for label). However, if for
example the sign (sense) of only some items (variables) of a scale have to be
recoded (e.g. reversed) such that all items correlate positively with each
other, their value labels should be recoded, as well. But if only one (or only
some) of the scale items have to be recoded (reversed) and the user is not aware
that their value label is shared with other items it may happen that recoding
this value label inadvertently recodes (reverses) the value label of the other
items, as well, resulting in improper value labels for some items and
consequently wrong conclusions from the analyses.

You could use elabel (from SSC) to avoid this. As an example:

. sysuse auto, clear
(1978 automobile data)

. keep foreign

. rename foreign item1
. clonevar item2 = item1
. clonevar item3 = item1

. // recode values of item1:

. recode item1 (0=1) (1=0)
(74 changes made to item1)

. // define a new value label "item1" with the old value label recoded:

. elabel recode (item1) (0=1) (1=0), def(item1)

. // assign the new value label to variable "item1":

. lab val item1 item1

. fre item? // requires -fre- from SSC

item1 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Foreign | 22 29.73 29.73 29.73
1 Domestic | 52 70.27 70.27 100.00
Total | 74 100.00 100.00

-+

item2 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Domestic | 52 70.27 70.27 70.27
1 Foreign | 22 29.73 29.73 100.00
Total | 74 100.00 100.00

-+

item3 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Domestic | 52 70.27 70.27 70.27
1 Foreign | 22 29.73 29.73 100.00
Total | 74 100.00 100.00

-+

But you can use renlabv to avoid altogether the problem of inadvertently
recoding value labels when recoding only some items of a set of items originally
assigned to the same value label. After having run renlabv you can then
use the tandem of recode and elabel recode -- without the option
define() -- to safely recode some of the scale items.

Of course, the issue renlabv is intended so solve is not only restricted
to scale items but to any value label that is assigned to several variables, for
example dichotomous variables with values coded 0 for "no" and 1 for "yes", etc.

Another use of renlabv might be that you import SPSS data containing variables
with value labels defined into Stata: Stata will automatically generate label
values named "labels0", "labels1", "labels2", etc. Running renlabv will
rename them to better recognizable names since they will match the names of the
assigned variables.

The disadvantage of using renlabv is that subsequently you cannot longer
use Stata's feature to relabel several variables simultaneously by redefining
their common value label. If this bothers you, you can call renlabv by
specifying only those variables which you actually want to recode.

Examples

Use renlabv to rename all value labels to match the name(s) of
the assigned variable(s) and recode only one item and its value label:

. sysuse auto, clear
(1978 automobile data)

. keep rep78 foreign

. label define notass 0 "no" 1 "yes"

. label define rep78 1 "poor" 5 "excellent"
. lab val rep78 rep78

. clonevar abroad = foreign
. clonevar item1 = foreign
. clonevar item2 = foreign
. clonevar item3 = foreign

. renlabv
. describe

Contains data from /usr/local/stata18/ado/base/a/auto.dta
Observations: 74 1978 automobile data
Variables: 6 13 Apr 2022 17:45
(_dta has notes)

Variable Storage Display Value
name type format label Variable label

rep78 int %9.0g rep78 Repair record 1978
foreign byte %8.0g foreign Car origin
abroad byte %8.0g abroad Car origin
item1 byte %8.0g item1 Car origin
item2 byte %8.0g item2 Car origin
item3 byte %8.0g item3 Car origin

Sorted by: foreign
Note: Dataset has changed since last saved.

. label dir
item3
item2
item1
abroad
foreign
rep78
notass

. // recode and relabel item1:
.
. recode item1 (0=1) (1=0)
(74 changes made to item1)

. elabel recode item1 (0=1) (1=0)

. fre item? // requires -fre- from SSC

item1 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Foreign | 22 29.73 29.73 29.73
1 Domestic | 52 70.27 70.27 100.00
Total | 74 100.00 100.00

-+

item2 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Domestic | 52 70.27 70.27 70.27
1 Foreign | 22 29.73 29.73 100.00
Total | 74 100.00 100.00

-+

item3 -- Car origin

-+

| Freq. Percent Valid Cum.

-+

Valid 0 Domestic | 52 70.27 70.27 70.27
1 Foreign | 22 29.73 29.73 100.00
Total | 74 100.00 100.00

-+

Use renlabv for renaming value labels to match the name(s)
of only some assigned variable(s):

. sysuse auto, clear
(1978 automobile data)

. keep rep78 foreign

. label define notass 0 "no" 1 "yes"

. label define rep78 1 "poor" 5 "excellent"
. lab val rep78 rep78

. clonevar abroad = foreign
. clonevar item1 = foreign
. clonevar item2 = foreign
. clonevar item3 = foreign

. renlabv item1 item2 item3

. describe

Contains data from /usr/local/stata18/ado/base/a/auto.dta
Observations: 74 1978 automobile data
Variables: 6 13 Apr 2022 17:45
(_dta has notes)

Variable Storage Display Value
name type format label Variable label

rep78 int %9.0g rep78 Repair record 1978
foreign byte %8.0g origin Car origin
abroad byte %8.0g origin Car origin
item1 byte %8.0g item1 Car origin
item2 byte %8.0g item2 Car origin
item3 byte %8.0g item3 Car origin

Sorted by: foreign
Note: Dataset has changed since last saved.

. label dir
item3
item2
item1
rep78
notass
origin

Returned results

Macros:

r(dvl) dropped value labels (if value labels have been dropped)

Author

Dirk Enzmann
https://www.wiso.uni-hamburg.de/fachbereich-sowi/ueber-den-fachbereich/personen/enzmann-dirk.html
dirk.enzmann@uni-hamburg.de

Acknowlegements

Thanks to Daniel Klein for assistance in solving my problems using elabel.

Also see

Online: label, recode

SSC package elabel: (click here)