Let me explain what characterize my observations to better understand what I want to realize.
I have two variables which characterize my treatment: framing (equal to 0 or 1) & sanctions (0, 1 or 2).
For each observation there are a deviation level (dev_inter1 variable between 1 and 7) and the punishment stage (Punished equal to 0 or to 1).
I want to make a graphic that reflects the likelihood of being punished depending on the deviation level but also of the framing (for the treatment sanctions==2). In this graphic I also want the numbers of observations (by deviation level and framing) to appear.
So I made these codes :
Code:
drop if sanctions != 2 egen percent = mean(100 * Punished), by (dev_inter1 framing) collapse percent (count) n=percent, by(framing sanctions dev_inter1) egen axis = axis(dev_inter1), gap label(dev_inter1) *** Test 1 : I could not make the number of observations appear. #delimit ; graph bar percent if sanctions==2, over(framing) over(dev_inter1) asyvars bar(1, color(red)) bar(2, color(blue)) blabel(n) title("Likelihood of being punished by deviation level and framing") ytitle("Likelihood of being punished") name(test1, replace); #delimit cr ***Test 2 : Here the number of observation appear but I could not add different color by framing and I find this graphic less clear. #delimit ; graph twoway bar percent axis if sanctions==2 || /// scatter percent axis if sanctions==2, by(framing, title("Likelihood of being punished by deviation level") legend(off)) ms(i) mlab(n) mlabpos(12) mlabcolor(black) || /// , ytitle("Average punishment points received") ylabel(0 (10) 110) xtitle("Deviation level") xlabel(1 "[-20,-14)" 2 "[-14,-8)" 3 "[-8,-2)" 4 "[-2,2]" 5 "(2,8]" 6 "(8,14]" 7 "(14,20]", labsize(small)) name(Likelihood_Punished_test, replace); #delimit cr
(But also add different color by framing in the test 2? )
PS: I am sorry I could not upload the graphic.
0 Response to Make number of the observations appear in graph bar or twoway bar
Post a Comment