Maybe you meant something like:
clear all
set more off
* example database
sysuse auto
keep make
clonevar make2 = make
describe
list in 1/5, nolabel
* what you want
foreach v of varlist make* {
encode `v', gen(new`v')
drop `v'
rename new`v' `v'
}
describe
list in 1/5, nolabel
Translated into plain English (although code is straightforward) this is: for each variable that starts with make, encode
it generating a new variable, then drop
the old one and rename
the new
one. Local macros are used. See help foreach
and help macro
for details.