help for vreverse9

Reverse existing categorical variable

vreverse9
varname
[if exp]
[in range]
, generate(newvar)
[valuelabelname(lblname)
removenumlabel
mask(str)]

Description

vreverse9 generates newvar as a reversed copy of an existing
categorical variable varname which has integer values and (usually)
value labels assigned. Suppose that in the observations specified
varname varies between minimum min and maximum max. Then

newvar = min + max - varname

and any value labels are mapped accordingly. If no value labels have been
assigned, then the values of varname will become the value labels of
newvar. newvar will have the same storage
type and the same display format as varname.

If varname possesses a
variable label or characteristics, these will also be copied. It is the user's
responsibility to consider whether the copied variable label and
characteristics also apply to newvar.

Any missing values in varname, whether system missing .
or any extended missing values from .a to .z are copied
unchanged to newvar. No attempt is
made to reverse such categories, but any value labels are copied.

This command ignores any value labels associated with varname for
values not present in the data specified.

The name vreverse9 signals not only that this version is slightly
different from the original vreverse but also that version 9 is
required (as this command uses levelsof).

Options

generate() is a required option specifying a new variable name.

valuelabelname() specifies a name for the new value labels. By
default newvar is used as the name for the new value labels; any existing
value labels under that name for the values of newvar will be overwritten.

removenumlabel specifies that a numeric prefix previously assigned
using numlabel to the value labels attached to varname should be
removed from the value labels attached to newvar. The value labels
attached to varname will not be modified, unless they are the value
labels named by valuelabelname().

Concretely, suppose you defined value labels for the values 1 to 5 of
rep78 and then used numlabel to add numeric prefixes to those
labels. By default, without the removenumlabel option, vreverse9
produces value labels attached to newvar that will start with "5. " "4. "
"3. " "2. " and "1. ". Specifying the removenumlabel option will strip
those prefixes. Note that a subsequent numlabel would add prefixes "1. "
"2. " "3. " "4. " and "5. ". See also mask() below.

mask() is for use with removelabel. If, and only if,
some mask() was specified when previously using numlabel,
then specify the same mask() now.

Examples

. sysuse auto, clear

. vreverse9 foreign, gen(Foreign)

. clear

. input testvar

1

2

3

4

5

.

.a

.z

end

. label def testvar 1 Admirable 2 Approved 3 Adequate 4 Alarming 5 Abysmal .a Unrecorded .z Irrelevant

. label val testvar testvar

. vreverse9 testvar, gen(wanted)

. version 17: table testvar wanted, missing

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

Acknowledgments

Original vreverse: Renzo Comolli pointed out an issue that can arise if numlabel
had previously been used.
Daniel Stegmueller alerted me to a problem with extended missing values.

This vreverse9: Felix Wilke also flagged problems with extended missing values.

Also see

Online: help for label, numlabel