Alicia Gonzalez
Alicia Gonzalez

Reputation: 11

How do I lowercase the contents of ALL string variables?

I'm trying to figure out an efficient way to lowercase all of the contents of string variables in Stata. I know how to do it one variable at a time (using example of a variable called VARIABLE), like

replace VARIABLE = lower(VARIABLE)

Is there a way to do it simply, such as using the following to lowercase all variable names:

rename *, lower

Upvotes: 1

Views: 7784

Answers (1)

Nick Cox
Nick Cox

Reputation: 37208

ds will give you a list of names of all string variables after which you can just loop over them in the usual way. See also findname (Stata Journal) for an alternative command to find names of variables satisfying certain conditions. The syntax using findname would be similar, findname, type(string).

ds, has(type string) 
foreach v in `r(varlist)' { 
    replace `v' = lower(`v') 
} 

Upvotes: 3

Related Questions