help revv


revv -- Reverse value order of variables


revv varlist [if] [in] [, options]

options Description ------------------------------------------------------------------------- prefix(str) use str as prefix for new variables generate(namelist) create new variables name1, ..., namek replace replace variables with reversed version valid(numlist) reverse all values specified in numlist define(namelist) define value labels and use name1, ..., namek as value label names nolabel do not define a value label for new variables numlabel handle numeric prefix in value labels -------------------------------------------------------------------------


revv reverses the value order of each variable specified in varlist. New variables are created containing the reversed value order of the original variables. Value labels are reversed accordingly.

Remarks: Variables are assumed to be Likert-type items with integer values incremented by one. If this is not the case specify valid(). revv is also able to handle variables that contain non-integer values.


+---------+ ----+ Options +----------------------------------------------------------

prefix(str) uses str as prefix for the new variables' names. Default prefix is rv_, meaning that reversed variables names are rv_varname.

generate(namelist) creates new variables name1, ..., namek. May be combined with prefix().

replace replaces variables in varlist with their reversed version. May not be combined with generate() or prefix().

valid(numlist) reverses values specified in numlist. In numlist (1 2 3 4) values 1 and 4 and values 2 and 3 are swapped. See example.

define(namelist) uses names as value label names for the created variables. Default is to use new variables' names as value label names.

nolabel specifies that no value labels will be defined for the new variables.

numlabel indicates that there is a numeric prefix assigned to the value labels by numlabel. If a numlabel command has been used previously value labels defined by revv will not be appropriate, unless numlabel is specified.


Suppose three variables containing information on respondents attitudes towards some issue. Variable var1 has values 1 'strongly agree' to 5 'strongly disagree', var2 has values 1 'very important' to 7 'not important at all' and var3 has values 1 'always' to 4 'never'. For some reason we want to reverse the value order of all three variables, so var1 has values 1 'strongly disagree' to 5 'strongly agree' and so on. We can do so typing something like:

. recode var1 (5 = 1)(4 = 2)(2 = 4)(1 = 5) ,prefix(rec_) . recode var2 (7 = 1)(6 = 2)(5 = 3)(3 = 5)(2 = 6)(1 = 7) ,prefix(rec_) . recode var3 (4 = 1)(3 = 2)(2 = 3)(1 = 4) ,prefix(rec_)

We get the same result (and appropriate value labels) typing:

. revv var1 var2 var3 ,prefix(rec_)

How to use the valid() option

. tabulate var1

var1 | Freq. Percent Cum. ------------------+----------------------------------- agree | 2 14.29 14.29 undecided | 3 21.43 35.71 disagree | 4 28.57 64.29 strongly disagree | 5 35.71 100.00 ------------------+----------------------------------- Total | 14 100.00

. label list var1 var1: 1 strongly agree 2 agree 3 undecided 4 disagree 5 strongly disagree 9 missing

Note that the minimum valid value in the data (which is 2) is not the theoretical minimum value in the underlying Likert-item (which is 1). Without specifying valid() you will get:

. revv var1

. tabulate rv_var1

rv_var1 | Freq. Percent Cum. ------------------+----------------------------------- strongly disagree | 5 35.71 35.71 disagree | 4 28.57 64.29 undecided | 3 21.43 85.71 agree | 2 14.29 100.00 ------------------+----------------------------------- Total | 14 100.00 . label list rv_var1 rv_var1: 1 strongly agree 2 strongly disagree 3 disagree 4 undecided 5 agree 9 missing

Note that 'strongly agree' is coded '2', whereas you want it to be coded '1'. Specifying the valid() option gives the appropriate result

. revv var1 ,valid(1/5)

. tabulate rv_var1

rv_var1 | Freq. Percent Cum. ------------------+----------------------------------- strongly disagree | 5 35.71 35.71 disagree | 4 28.57 64.29 undecided | 3 21.43 85.71 agree | 2 14.29 100.00 ------------------+----------------------------------- Total | 14 100.00

. label list rv_var1 rv_var1: 1 strongly disagree 2 disagree 3 undecided 4 agree 5 strongly agree 9 missing


There are several programs that serve the same purpose as revv. The omscore command written by Marc Jacobs in 1992, revrs by Kyle C. Longest, reverse by Johan Martinsson (which is not available form SSC yet) and the vreverse command by Nicholas J. Cox, to name a view. Implemented in official Stata there is the gsort command which can (in some cases) be used to reverse the value order of variables. Looking at these programs was very helpful writing revv. I have tried to combine their strengths and overcome their shortcomings.

revv enables the user to specify a list of variables (as revrs and gsort) rather than only one variable and allows a user defined name for the created new variables (as reverse, vreverse and gsort). Extended missing values are left unchanged and copied to the new variable (as revrs does). revv handles non-integer values and the user may specify valid values that are not in the data. The command applies to value labels, too (as revrs and vreverse). Value labels are reversed for all valid values (either in the data or given by the user) and left unchanged if there are no corresponding valid values. revv can also handle a previously used numlabel command (probably not as well as vreverse does though).


Daniel Klein, University of Bamberg,

Also see

Online: gsort, recode, label

if installed: omscore, revrs, vreverse