Hi Statalist community,

I am using the voter.dta dataset as an example. I am using the tabulate command to create a series of dummy variables from a categorical variable called candidat. For each of the dummy variables I created, I want to revise the variable label so that it identifies each category of the original categorical variable candidat. When I use the tabulate command, the variable labels begin with candidat== but I want all the characters after the == symbols. It's not a problem for me to manually rename each variable label since this dataset is small but it is a pain when I have a categorical variable with many categories. I tried writing a loop below but could not get it to work. Any help would be appreciated.


Code:
clear all
*Call in data
webuse voter.dta
*Create a dummy variable for each of three candidates
tabulate candidat , gen (dum_cand)

**This is what I am aiming to accomplish.
*Rename variable labels
label variable dum_cand1 "Clinton"
label variable dum_cand2 "Bush"
label variable dum_cand3 "Perot"

*This is the loop that I tried to write but doesn't work.
*Create a loop to label the variable
foreach var of varlist dum_cand1-dum_cand3 {
    label variable `var' `=substr("`var'", "==")'
}