Stata command to lowercase all variable names or the values of all string variables

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:

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.

This entry was posted in Stata. Bookmark the permalink.

2 Responses to Stata command to lowercase all variable names or the values of all string variables

  1. steve says:

    Is it the same with
    rename _all, lower

Leave a Reply

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