rename var17 varx17
will change the name of variable var17 to varx17. Note that obviously you cannot use variable lists here; rather, for each variable to be renamed a new command line has to be written.
Several variables can be renamed with a single command, as in:
rename (var17 var45 var83) (trust income age)
You may also interchange variable names:
rename (var17 var19) (var19 var17)
Tricks and shortcuts
The asterisk serves as a wildcard to indicate parts of variables names (or entire variable names) that will be left unchanged in the renaming process. Thus,
rename V* v*
will rename all variables that start with capital "V", replacing it by a small "v". Or,
rename * *_2
will append "_2" to all variable names, while
rename v* *a
will remove any leading "v" from variable names and will append an "a" to these variables. (This is just a short and simple example. Please remember that variable names have to start with a letter or an underscore, so if you have variable names like "v1" etc., this command would not be applied to these variables.)
In contrast, the question mark stands for a single character in a variable name. But let me refer here to the Stata help at
help rename group.
Older versions of Stata
The "tricks and shortcuts" mentioned were introduced with Stata 12.0. Prior to that, some other commands such as the following were available:
renpfix male m
changed the name of all variables that start with "male" by replacing "male" with "m" only.
© W. Ludwig-Mayerhofer, Stata Guide | Last update: 21 Mar 2019