Renaming Variables in Stata - The Rename Command

Sometimes when you import a new dataset or create a new dataset you realise that the variable names are not appropriate for the work you are doing. Perhaps they do not match the variables in another dataset that you want to merge in, or the names may just be long and cumbersome to type. 

To address this problem Stata has the rename command.  This command can be used to change the name of a variable to something else. You can use it to change variable names to all lower case, all upper case, or have the first letter of each variable name capitalised.  The rename command also has a useful group function, where you can use it to rename all the variables in your dataset at the same time.

How to Use:

Change var1 to var2:

rename var1 var2

Change var1 to all upper case (VAR1):

rename var1, upper

Change VAR1 to all lower case (var1):

rename VAR1, lower

Change var1 to proper case (Var1):

rename var1, proper

Change all variable names to lower case:

rename *, lower

Worked Example:

In this example I use the auto dataset, which can be loaded using the command below.

sysuse auto, clear

The rename command can be used to rename single variables, or alternatively all the variables in a dataset. To change the name of a single variable you use that variable name in the command, as shown in the How to Use section above. In this example I am going to rename the variable “make” to “make_model”, and then rename all variables to upper-case. I use the command describe to show the difference.

In the command pane I type the following:

rename make make_model
describe

rename *, upper
describe

Here you can see that firstly “make” is renamed as “make_model”. Then, by using “*” instead of a variable name, all the variables are changed to upper-case.