Dear Stata - Community,
I am using the "catplot" command to create a graph with multiple stacked horizontal bars. The four categorical variables being used are having the same categories. In the end, I would like to have a graph similar to the one attached in this post.
Yet, after reshaping my data, I am still facing the problem that I have too many binary variables (indicating the respective categorical variable) to run the catplot command (please see a simplified version of my code below). I tried to group these variables, modify the setting of the command and using other command, but in the end it still did not work. Can anyone help?
Thanks for any help in advance!
Warm greetings, Bianca
I am using the "catplot" command to create a graph with multiple stacked horizontal bars. The four categorical variables being used are having the same categories. In the end, I would like to have a graph similar to the one attached in this post.
Yet, after reshaping my data, I am still facing the problem that I have too many binary variables (indicating the respective categorical variable) to run the catplot command (please see a simplified version of my code below). I tried to group these variables, modify the setting of the command and using other command, but in the end it still did not work. Can anyone help?
Thanks for any help in advance!
Warm greetings, Bianca
Code:
** four categorical vars with same categories local vars1 x1 x2 x3 x4 ** gen binary variables for each category of the four vars foreach var of local vars1{ tab `var' , gen(`var'_cat_) } ** reshape data gen id = _n reshape long x1_cat_ x2_cat_ x3_cat_ x4_cat_, i(id) ** define labels of newly created _j var label variable _j "" label define _j 1 "Strongly agree" 2 "Agree" 3 "Neither agree nor disagree" 4 "Disagree" 5"Strongly disagree" 6 "No answer" label value _j _j ** catplot * for one var, the following command works perfectly catplot _j , over(x1_cat_) percent(x1_cat_) asyvars stack * yet, I need a command to combine all vars in one hbar --> the following command would be needed, but does not work (too many variables) catplot _j , over(x1_cat_ x2_cat_ x3_cat_ x4_cat_) percent(x1_cat_ x2_cat_ x3_cat_ x4_cat_) asyvars stack
Comment