I have written the ultimate guide on renaming variables in Stata. Sometimes, we need to rename the existing variables names. There may be multiple reasons to change the variable names. For example, the name of a variable is too long and when you do analysis in Stata, the name of variable appeared weirdly in the data table. Therefore, renaming of a variable is required for this.

There are numerous commands to change variables’ names. In this conclusive guide, I have listed all the commands and techniques to rename variables in Stata.

Data Description

I have used the built-in data set from Stata software. The data set have values of Automobile sector of 1978. To use the data set, use following code:

sysuse auto2.dta

To see what variables in the data are, we use the following command:

Describe Variables In Stata
Describe Variables In Stata

Change variable Name in Stata:

In above picture, we can see that there are different variables. For example, mpg is a variable which means Mileage. If we want to change this variable name from mpg to mileage, use the following command:

rename mpg mileage

 To see the updated variable names, use describe command again:

Describe Variables After Renaming Variable In Stata
Describe Variables After Renaming Variable In Stata

We can see now that variable name mpg has been changed to mileage.  In this way, we can rename variables in Stata.

An ultimate list of Commands and Techniques to rename variables in Stata

The following is a complete list of commands and techniques to rename variables in Stata. I will use the mpg variable as an example for this list:

Simple rename one variablerename mpg mileage
Change variable name to upper caserename mpg, upper
Change variable name to lower caserename mpg, lower
Use * to change all variablesrename *, upper
Change variable name to proper caserename mpg, proper
Rename multiple variablesrename (mpg rep78 turn) (mileage repair_record trunk_space)
Rename all variables starting with rep to Reprename rep* Rep*
Remove rep prefix word from all variablesrename rep* *
Remove rep suffix word from all variablesrename *rep *
Get official rename guide from Statahelp rename


This guide explains all of the commands and techniques used to rename variables in Stata. While working on Stata for data analysis, it is essential to know the process of renaming a variable. Sometimes, an unwanted name was given to a variable by default. Therefore, rename command is a handy command for data analysis in Stata.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *