Introduction
Oftentimes, you might work with datasets in which variables need to be renamed. In this blog, we’ll show you how to rename variables in Stata.
Load Data
Try the following code to load your data:
sysuse auto
describe
As you can see, these are data pertaining to automobiles:
Renaming a Variable: Two Approaches
If you want to be really cautious, you needn’t rename a variable. You can clone a variable and give it a new name. Let’s try creating a new variable named repair that is exactly the same as rep78, with the only difference being the variable name itself:
clonevar repair = rep78
order rep78 repair
edit
As you can see in your edit window, repair is the cloned version of rep78, which is still in the dataset:
On the other hand, if you really want to rename a variable, you can do so as well. Let’s rename mpg as MPG, noting that variable names are case-sensitive in Stata. Try:
rename mpg MPG
In this syntax, the first variable (mpg) is what you are renaming, and the second variable (MPG) is what you are renaming the first variable to.
Now:
sum MPG
Shows you that the variable has indeed been renamed:
BridgeText can help you with all of your statistical analysis needs.