Stata is a case-sensitive application. Sometimes this will cause a trouble. So, we may want to change variable names or values of variables to all lowercase before we start processing data. This post gives a fast way to do this.
Change variable names to all lowercase
We need to use the command rename
. Instead of renaming variables one at a time, we can rename all variables in a single command (thanks Steve):
1 |
rename _all, lower |
A related post can be found here: http://kaichen.work/?p=1483.
Change values of string variables to all lowercase
ustrlower(string_variable)
or strlower(string_variable)
will do the trick. Instead of applying ustrlower
or strlower
function to string variables one by one, we can benefit from lowercasing values of all string variables in a short loop. The following loop will first check the type of a variable. If it is a string variable, then change the value of the variable to all lowercase.
1 2 3 4 5 6 |
foreach var of varlist _all { local vartype: type `var' if substr("`vartype'",1,3)=="str" { replace `var'=ustrlower(`var') } } |
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.