*! version 3.0.0 4/23/92
capture program drop fold
program define fold
        version 3.0
        local varlist "req ex min(3)"
        parse "`*'"
        parse "`varlist'", parse(" ")
        confirm new var _`1'
        confirm new var _`2'

        capture {
               sort `1'
               egen _`2'=sum(`2'), by(`3')
               rename `2' _`1'
               keep if `1'==1
               drop `1'
               drop `2'
        }
        noisily di in bl " Data set folded..."

end