Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: New SSC module: -revrs- to reverse order and keep labels


From   Kyle C Longest <[email protected]>
To   [email protected]
Subject   st: New SSC module: -revrs- to reverse order and keep labels
Date   Tue, 17 Apr 2007 08:46:16 -0400

Thanks to Kit Baum, a new program, -revrs-, is available on SSC.

. ssc install revrs

-revrs- is a module to reverse the order of a variable's values and maintain specified value labels. �revrs- is especially helpful for quickly recoding multiple categorical or ordinal response variables to follow a similar direction.

Version 8.2 of Stata required.

The primary purpose of the program is to allow users to reverse order variables in one step, and keep the value labels. This is helpful in cases when surveys will ask similar questions but switch the direction of the response categories (e.g., is �Never� coded as 0 or as 5). Granted most Stata programs will inherently control for this reverse ordering, but this program can be helpful for aesthetic (e.g., frequency distributions, cross tabs) purposes (especially if the user is directly copying tables out of Stata) and to reduce possible confusion (e.g., interpreting negative coefficients).

Example:

. tab drink

drink | Freq. Percent Cum.
-------------------+-----------------------------------
Every_Day | 99 9.90 9.90
Almost_Every_Day | 101 10.10 20.00
Once a Week | 40 4.00 24.00
Once A month | 159 15.90 39.90
A few times a Year | 301 30.10 70.00
Never | 300 30.00 100.00
-------------------+-----------------------------------
Total | 1,000 100.00

. revrs drink

. tab revdrink

revdrink | Freq. Percent Cum.
-------------------+-----------------------------------
Never | 300 30.00 30.00
A few times a Year | 301 30.10 60.10
Once A month | 159 15.90 76.00
Once a Week | 40 4.00 80.00
Almost_Every_Day | 101 10.10 90.10
Every_Day | 99 9.90 100.00
-------------------+-----------------------------------
Total | 1,000 100.00


-revrs- accepts a variable list, and without any options will create a new variable with �rev� appended to the front of the original variable(s) name. The �REPLace- option automatically overwrites the original variable (keeping its name) with the reversed version. Finally, it must be noted that �revrs- does not deal with the values themselves, only their order. So if the actual values are of importance, an extra step would be needed.

The program utilizes Roger Newsom�s �sencode- which will be installed (if not already) alongside �revrs- when done from inside Stata.

Hopefully it will be as helpful in saving time and headaches for others as it has for me, and suggestions and comments are, as usual, more than welcomed.

Thanks, Kyle C. Longest
Dept. of Sociology
University of North Carolina � Chapel Hill
[email protected]




*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index