*! 1.1.0  20Oct96  Jeroen Weesie/ICS
*     --  added support for string variables
*     --  added support for display formats
*  1.0.0  01Oct96  Jeroen Weesie/ICS

capt program drop summvl
program define summvl
    version 5.0

    local varlist "opt ex"
    local if      "opt"
    local in      "opt"
    local weight  "fweight aweight"
    local options "Format(str) Same Wide"
    parse "`*'"

    if "`format'" != "" {
        capture local f : display `format' 1
        if _rc {
            di in re "invalid format `format'"
            exit 120
        }
    }
    else  local format %8.0g

    tempvar touse
    mark `touse' `if' `in' [`weight'`exp']
    if "`same'" != "" {
        * option -strok- allows string-variables in -varlist-
        markout `touse' `varlist', strok
    }

    quietly count if `touse'
    if _result(1) == 0 {
        di in bl "no observations"
        exit 0
    }

    di in gr _n "Variable  Obs     Mean  Std.Dev     Min     Max   Label (29 chars)"
    di in gr    _dup(79) "-"

    parse "`varlist'", p(" ")
    while "`1'" != "" {
        local vlab : var label `1'
        if "`wide'" == "" & length("`vlab'") > 29 {
            local vlab = substr("`vlab'",1,29)
        }
        local vt : type `1'
        if substr("`vt'",1,3) == "str" {
            di in gr "`1'" in ye _col(10) "<string>" in wh _col(51) "`vlab'"
        }
        else {
            * local vf : format `1'
            if "`format'" != "" { local vf "`format'" }
            quietly summ `1' if `touse' [`weight'`exp']
            #del ;
            di in gr "`1'"
               in ye _col(10) %4.0f _result(1)
                     _col(15) `vf'  _result(3)
                     _col(24) `vf'  sqrt(_result(4))
                     _col(33) `vf'  _result(5)
                     _col(41) `vf'  _result(6)
               in wh _col(51) "`vlab'" ;
            #del cr
        }
        mac shift
    }
    if "`weight'" != "" {
       di in gr _dup(79) "-" _n /*
       */ in bl "results are weighted using [`weight'`exp']"
    }
end