You don't need to do that. You don't need a loop and you don't need that syntax. Consider
. sysuse auto, clear
(1978 Automobile Data)
. ds
make mpg headroom weight turn gear_ratio
price rep78 trunk length displacement foreign
. rename *, upper
. ds
MAKE MPG HEADROOM WEIGHT TURN GEAR_RATIO
PRICE REP78 TRUNK LENGTH DISPLACEMENT FOREIGN
Otherwise you are puzzled at the
`= '
because indeed that is nothing to do with rename. That syntax obliges Stata to evaluate a scalar expression on the fly so that rename sees only the result of that expression. In your case the string expression
upper("`var'")
yields an upper-case version of the variable name contained in local macro var.
This syntax is documented at help macro and [P] macro (e.g.
in this version p.13) as one kind of expansion operator.
All that said, all variable names upper case is horrible style....