*! 1.0.1 NJC 29 January 1999
* 1.0.0 17 June 1997
program define _grev
        version 5.0
        local type "`1'"
        mac shift
        local g "`1'"
        mac shift
        mac shift                               /* discard = sign */
        local varlist "req ex max(1)"
        local if "opt"
        local in "opt"
        local options "by(string)"
        parse "`*'"
        if "`by'" != "" {
                confirm variable `by'
                sort `by'
                local byby "by `by' :"
        }
        qui `byby' gen `type' `g' = `varlist'[_N - _n + 1] `if' `in'
end