Stata is a case-sensitive application, which can sometimes cause trouble. Therefore, we might want to convert all variable names or the values of all string variables to lowercase before further data processing. This post gives a quick method to do this.
Lowercase all variable names
The rename
command is used for this purpose. Instead of renaming variables one by one, we can rename all variables with a single command:
rename *, lower
or rename _all, lower
A related post can be found at https://www.kaichen.work/?p=1967. Mingze Gao wrote a macro to achieve the same function in SAS (here).
Lowercase the values of all string variables
ustrlower(string)
or strlower(string)
will do the trick. Instead of applying the ustrlower
or strlower
function to string variables individually, we can benefit from lowercasing the values of all string variables in a short loop:
1 2 3 4 |
ds, has(type string) foreach v in `r(varlist)' { replace `v'=strlower(`v') } |
In this loop, ds
is used to find string type variables and foreach
is used to iterate over each string variable to replace its values with the lowercase version.
Is it the same with
rename _all, lower
Thanks for your input. I realize the original post is ambiguous. I have made an update to make it clearer.