Hello everyone,
I have truly scoured this board and furiously Googled and at this point I have questioned whether the inability to find the answer to this (seemingly) simply question has more to do with me not using the correct terminology than it is that the answer is not currently posted. I also might be missing something very obvious and if that's the case I apologize in advance. I am using Stata 17/BE.
I have 15 binary variables for which I would like to summarize the proportions (presented as percents) across two groups in a horizontal bar graph. I would like to display all 15 variables on one graph with each variable listed on the y-axis split by the means for two groups. Using -graph hbar- I can obtain the summaries for Group 1 - Summary of all ones for all 15 variables and Group 2 - Summary of all ones for all 15 variables, but I would like Var1 - Group1 Group2, Var 2 - Group1 Group 2.
An example of my original data is:
I created a new variable for each variable that summarizes the percent of 1s for each group, which is why the naming below is "soc_good_1_pc" instead of "soc_good_1". These variables are calculated by finding the mean of each variable when your_group=1 and then when your_group=0 then generating a percent variable and replacing it with the correct percent if your_group = 1 or your_group = 0.
Using the code:
I get:

However, I'd rather have mean of soc_good_1_pc (I will tidy these labels up once I can address this issue presented here) then Norm Group and Your Group as red or blue, so I'd be showing the side-by-side comparisons of the mean for each group by each variable.
After reviewing the forum, I did read up on catplot and I was able to create the side by side comparisons for one binary variable, but I cannot seem to add multiple variables, but I would like all 15 variables listed in a horizontal graph. I am also not interested in displaying the percent of 0s. I used this code:
I get the following. I am wanting the results for the "1" for all 15 variables:

The only solution I am thinking I could try is to create a new variable with only 1-15 _N observations and each observation is simply the label for the original variable(example name: socwb_variable_names),then create two new variables for each of my original variables one with the percent "your group" (example name: socwb_good_pc_your) and the percent of "norm group" (example name: socwb_good_pc_norm) listed in the corresponding 1-15 observations. It would look something like:
Then, I could create a graph using the following code:
This seems like a lot of additional steps to basically present tabulations of each variable by two groups for 15 variables.
Thank you in advance for all of your help and suggestions!
-Ashleigh
I have truly scoured this board and furiously Googled and at this point I have questioned whether the inability to find the answer to this (seemingly) simply question has more to do with me not using the correct terminology than it is that the answer is not currently posted. I also might be missing something very obvious and if that's the case I apologize in advance. I am using Stata 17/BE.
I have 15 binary variables for which I would like to summarize the proportions (presented as percents) across two groups in a horizontal bar graph. I would like to display all 15 variables on one graph with each variable listed on the y-axis split by the means for two groups. Using -graph hbar- I can obtain the summaries for Group 1 - Summary of all ones for all 15 variables and Group 2 - Summary of all ones for all 15 variables, but I would like Var1 - Group1 Group2, Var 2 - Group1 Group 2.
An example of my original data is:
| soc_good_1 | soc_good_2 | soc_good_3 | soc_good_4 | soc_good_5 | ...soc_good_15 | your_group |
| 1 | 1 | 0 | 1 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 | 0 |
| ... | ... | ... | ... | .. | ... | ... |
Using the code:
Code:
graph hbar (mean) soc_good_1_pc (mean) soc_good_2_pc, over(your_group, relabel(1 "Your Group" 0 "Norm Group"))
However, I'd rather have mean of soc_good_1_pc (I will tidy these labels up once I can address this issue presented here) then Norm Group and Your Group as red or blue, so I'd be showing the side-by-side comparisons of the mean for each group by each variable.
After reviewing the forum, I did read up on catplot and I was able to create the side by side comparisons for one binary variable, but I cannot seem to add multiple variables, but I would like all 15 variables listed in a horizontal graph. I am also not interested in displaying the percent of 0s. I used this code:
Code:
catplot your_group socwb_good_1, asyvars percent(your_group) blabel(bar)
The only solution I am thinking I could try is to create a new variable with only 1-15 _N observations and each observation is simply the label for the original variable(example name: socwb_variable_names),then create two new variables for each of my original variables one with the percent "your group" (example name: socwb_good_pc_your) and the percent of "norm group" (example name: socwb_good_pc_norm) listed in the corresponding 1-15 observations. It would look something like:
| socwb_variable_names | socwb_good_pc_your | socwb_good_pc_norm |
| name1 | 54 | 43 |
| name2 | 23 | 36 |
| name3 | 40 | 42 |
| name4 | 31 | 54 |
| ... | ... | ... |
| name15 | 54 | 54 |
Code:
graph hbar (mean) socwb_good_pc_your (mean) socwb_good_pc_norm, over(socwb_variable_names))
Thank you in advance for all of your help and suggestions!
-Ashleigh

Comment