*! version 1.1 -- revised 5/22/03
program define tablist
  version 7
  syntax varlist [if] [in] [, Sort(string) Freq(string) *]

  preserve

  if "`freq'" == "" {
    local freq = "Freq"
  }
  contract `varlist' `if' `in' , freq(`freq')
  format `freq' %5.0f
  if "`sort'" == "v" {
    gsort `varlist'
  }
  else if "`sort'" == "+f" {
    gsort +`freq'
  }
  else {
    gsort -`freq'
  }
  list `varlist' `freq' , noobs `options'

  restore

end