How to rename all the variable names in STATA at once?
Nov 1, 2023
Suppose we have a data set like below.
And after editing on it we forgot to trace where we did edit, but now someone want to know the changes we made.
For this we want to rename all the variables with suffix ‘new’ or something else. So that we can compare it with our old data in future.
Now we can do this easily in stata with a loop no matter how many variables we have.
foreach v of varlist * {
rename `v' `v'_new
}s
By this all our variable name will be change
We can also change specific variables such as Name and age only.
local vars Name Age
foreach v in `vars'{
rename `v' `v'_new
}
See, just Name and Age changed.