-------------------------------------------------------------------------------
help for vreverse
-------------------------------------------------------------------------------

Reverse existing categorical variable

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

Description

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

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, vreverse 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

. vreverse foreign, gen(Foreign)

Author

Nicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk

Acknowledgements

Renzo Comolli pointed out an issue that can arise if numlabel had previously been used.

Also see

Online: help for label, numlabel