Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How change bars to dots that show averages?

    Hi! How can I replace the bars (that shows the average for each case) with red dots?

    This is my code:
    *Box plot with CI
    collapse (mean) Aprobacióndelgobierno (semean) sd = Aprobacióndelgobierno, by(PresentaAC)
    gen yu = Aprobacióndelgobierno + 1.96*sd
    gen y1 = Aprobacióndelgobierno - 1.96*sd

    twoway (bar Aprobacióndelgobierno PresentaAC, barw(0.15)) || (rcap yu y1 PresentaAC), legend(order(1 "Aprobación Promedio" 2 "IC")) xlabel(0 "No" 1 "Sí") ytitle(`"Aprobación de Gobierno (%)"') ylabel(, angle(horizontal))
    graph export 1_1_Apro_y_presenta_o_no_AC_con_test.png, replace

    Best regards,
    Andrés

  • #2
    A bar chart with superimposed confidence intervals is not best called a box plot, which by overwhelming convention is a term reserved for a display based on medians and quartiles with some detail in the tails of each distribution, quite what detail varying from implementation to implementation.

    There is no data example here -- please read and act on FAQ Advice #12.

    Aprobacióndelgobierno means, I gather, government approval, and is likely to be an indicator variable with values 1 or 0. That also seems to be the implication of your previous thread https://www.statalist.org/forums/for...a-twoway-graph

    In general, confidence intervals that are means +/- 1.96 standard errors are at best optimistic large-sample approximations assuming normal or Gaussian sampling distributions. Specifically for indicator variables good confidence intervals may be quite different and not even symmetric. See the help for ci and its references.

    Brown, L. D., T. T. Cai, and A. DasGupta. 2001. Interval estimation for a binomial proportion. Statistical Science 16: 101-133 still stands as an outstanding survey. https://projecteuclid.org/journals/s...009213286.full

    I would use statsby and ci proportion here, not collapse. See https://journals.sagepub.com/doi/pdf...867X1001000112 noting that the syntax of ci has changed since that paper.

    Here's a reproducible example. The first graph shown here shows that sensible y axis labels are 0.16(0.01)0.19: the code shows how to show %s instead.

    Clearly your details will differ. I have now answered your main question. If you prefer a scatter plot, rather than a bar chart, ask for a scatter plot using scatter not a bar chart with twoway bar.

    The jeffreys method is just a choice, but i think it's a good one.

    Code:
    webuse nlswork, clear
    
    statsby, by(nev_mar) clear : ci proportion collgrad, jeffreys
    
    scatter mean nev_mar, mc(red) || rcap lb ub nev_mar, lcolor(red) xla(0 1, valuelabel) aspect(1) xsc(r(-0.2 1.2)) legend(off) ytitle("mean and 95% confidence interval" "for proportion college graduate (Jeffreys method)") ylabel(, format(%03.2f)) name(G1, replace)
    
    scatter mean nev_mar, mc(red) || rcap lb ub nev_mar, lcolor(red) xla(0 1, valuelabel) aspect(1) xsc(r(-0.2 1.2)) legend(off) ytitle("mean and 95% confidence interval" "for % college graduate (Jeffreys method)") ylabel(.16 "16" .17 "17" .18 "18" .19 "19", format(%03.2f)) name(G2, replace)

    Click image for larger version

Name:	hernandezG1.png
Views:	1
Size:	30.2 KB
ID:	1757204



    Comment

    Working...
    X