Hello! I have two categorical variables ("concerned_chemicals" and "concerned_bacteria") with the same label values (1="Not concerned", 2="Somewhat concerned", 3="Moderately concerned" 4="Very concerned")
I would like to create a barplot showing the counts for each label for both variables overlaid onto the same graph. On the x-axis, I would like the four variable labels, and for each label, one bar showing the counts for "concerned_chemicals" and another bar next to it showing the counts for "concerned_bacteria".
I've tried using catplot to do so, but when I use the command "catplot concerned_chemicals concerned_bacteria" or "catplot concerned_chemicals, over(concerned_bacteria)", it gives me a nested graph, which is not what I want.
thank you for any input!
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(concerned_chemicals concerned_bacteria)
2 2
1 1
4 2
4 4
1 1
2 2
1 1
1 2
1 3
3 1
1 1
1 1
4 2
4 4
2 1
1 2
3 1
3 1
1 1
1 1
4 1
1 1
2 3
1 1
1 1
1 2
1 1
4 3
4 4
4 3
3 2
2 1
3 3
1 1
2 1
3 1
1 1
1 1
3 1
1 1
1 1
4 2
1 1
1 1
1 1
1 1
1 1
2 2
1 1
1 1
1 2
3 2
3 3
2 2
1 1
2 1
1 1
2 2
3 1
2 2
2 2
1 1
2 1
1 1
2 2
2 2
2 2
1 3
2 1
1 2
1 1
1 1
1 1
4 1
2 2
2 2
1 1
4 4
2 2
2 2
1 1
4 4
1 3
2 1
3 1
2 3
4 1
1 1
1 1
4 1
3 3
3 2
1 2
2 3
1 1
1 1
4 2
1 1
1 2
1 1
end
label values concerned_chemicals concerned
label values concerned_bacteria concerned
label def concerned 1 "Not at all concerned", modify
label def concerned 2 "Somewhat concerned", modify
label def concerned 3 "Moderately concerned", modify
label def concerned 4 "Very concerned", modify
[/CODE]
Related Posts with Bar chart for two categorical variables with same value labels
How to get p-Value & CI of each factor variable for a prevalence table?I can only explain this question through an example and I cannot go for a logit or logistic. This i…
How I can test if price elasticity in a quantile regression differs among quantiles?Dear statalists, I would like to ask you how I could test if price elasticity differs statisticall …
eventstudy2 command: Estimation Window spans both before and after the event windowI am using the eventstudy2 command. In my research design, the estimation window spans before and af…
Disable the Stata to recognise a variable by part of the variable nameI have tried to search for similar question but couldn't find any. So I hope to create a new questio…
Median Follow-up timeHello, could somebody give me an advice on how to calculate median follow-up time? Thank you very mu…
Subscribe to:
Post Comments (Atom)
0 Response to Bar chart for two categorical variables with same value labels
Post a Comment