This is cleaned up a bit from my previous posting:
*! 1.0.1 NJC 31 May 2007
program reversev
version 9
syntax varlist(numeric) [if] [in] , min(int) max(int)
marksample touse
qui count if `touse'
if r(N) == 0 error 2000
if `min' > `max' {
di as err "`min' > `max'"
exit 498
}
else if `min' == `max' {
di as err "`min' = `max'"
exit 498
}
foreach v of local varlist {
capture assert `v' == int(`v') if `touse'
if _rc {
di as err "non-integer values in `v'"
exit 498
}
}
quietly foreach v of local varlist {
clonevar new_`v' = `v' if `touse'
replace new_`v' = `min' + `max' - `v'
forval i = `min'/`max' {
local j = `min' + `max' - `i'
local lbl : label (`v') `j'
label def new_`v' `i' `"`lbl'"', modify
}
label val new_`v' new_`v'
}
end
*
* 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/