Hi Statalist community,
Below is a toy dataset. There is a categorical variable called foreign and I want to create dummy variables for it. Then I manually label the dummy variables with their respective variable values.
In this toy dataset, there is also the categorical variable make which has a lot of levels. If I want to create dummy variables for the categorical variable make and then manually label the dummy variables with their respective variable values, it would take a long time. Is there a more efficient way to rename these dummy variables?
Below is a toy dataset. There is a categorical variable called foreign and I want to create dummy variables for it. Then I manually label the dummy variables with their respective variable values.
Code:
*Call in dataset clear all webuse auto.dta *Identify the variable values for the variable of interest. tab foreign, mi *Create dummy variables for each level within the categorical variable. tab foreign, gen(Dum_foreign) *Rename the dummy variables with their variable values rename Dum_foreign1 Domestic rename Dum_foreign2 Foreign
Comment