program define varcase
** version 0.0.1     <JRG>
*! Syntax:	. varcase [ <varlist> ]
*! Toggle the case of <varlist>, from upper to lower, or vice-versa

   version 5.0
   local varlist "opt ex min(1)"
   parse "`*'"
   parse "`varlist'", parse(" ")

   local j 1
   while "``j''" != "" {
      local i 0
      local x
      local T = length("``j''")
      while `i' < `T' {
         local i = `i' + 1
         local ai = substr("``j''", `i', 1)
         local Ai = upper("`ai'")
         if "`Ai'" == "`ai'" { local Ai = lower("`ai'") }
         local x "`x'`Ai'"
      }
      cap confirm new var `x'
      if _rc { di in re "`x' already exists; can't rename ``j''" }
      else { qui rename ``j'' `x' }
      local j = `j' + 1
   }

end