* ver 2.0 Stas Kolenikov
program def takelogs
        version 7.0

        syntax varlist, [Decimal DOUBLE]

        tokenize `varlist'

        qui nobreak {
          while "`1'"~="" {
            g `double' l`1'=log(`1')
            lab var l`1' "Log `1'"
            if "`decimal'"~="" {
                replace l`1'=l`1'/log(10)
                lab var l`1' "Decimal log `1'"
                }
            mac shift
          }
        }
end

exit

Version 2.0: re-written for Stata 7