Announcement

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

  • Bar graphs with brackets to indicate statistical significance

    Dear statalist members,

    I would like to produce a bar graph with the (mean) differences for two different variables between two treatment groups. Producing this graph is not a problem; however, I would like to indicate the statistical significance of the (mean) differences between the treatments for each variable by using brackets and some text_options (?) (i.e., n.s. or the corresponding asterisks and/or the p-values). I attached two exemplary bar graphs, which I found online from other forums.

    How can I modify the following code to insert such brackets?
    graph bar variable_a variable_b, over(treatment) ///
    legend(label(1 "aa") label(2 "bb")) ///

    I would greatly appreciate any help on this.

    Many thanks and best,
    Tugba
    Attached Files
    I use a bar graph to indicate the data of each group. Some of these bars differ significantly from each other. How can I indicate the significant difference in the bar plot? import numpy as np imp...

  • #2
    You won't be able to do this using the graph command but with some work, you can do it with twoway. See the following:

    https://www.statalist.org/forums/for...raphs-in-stata

    Comment


    • #3
      Dear Andrew,

      thank you very much for your suggestion. I eventually decided to update the figure with the free vectors graphic editor Inkscape.

      Best,
      T

      Comment


      • #4
        Dear Stata Users,

        I want to draw the bar chart showing the cigarette brands smoked by gender. However, I do not know how to show significant differences in cigarette brands smoked between males and females? How can I show the significant differences on a bar graph? The cigarette brand is a categorical variable of 5 brands of cigarettes, and gender is a dummy variable which equals 1 if a respondent is male and 0 if a female.

        Regards,
        Pokothoane

        Comment


        • #5
          I would really like to follow-up on Tugba's post? I appreciate Andrew's redirect, but I'm just not sure how to do the same thing on the bar twoway space and it also seems like a really painful workaround.

          Could anyone help? I'd like to make exactly the same graphs Tugba wanted.

          Comment


          • #6
            Two scatteri calls, one with option -recast(line)- and the second with option -recast(dropline)- and a defined base should do it.

            Code:
            sysuse pop2000, clear
            replace maletotal = maletotal/1e+6
            tw (bar maletotal agegrp in 1/5) ///
               (scatteri 10.75 2 10.75 3,  recast(line) lw(medthick)  mc(none) lc(black) lp(solid)) ///
               (scatteri 10.75 2 10.75 3,  recast(dropline) base(10.6) lw(medthick) mc(none) lc(black) lp(solid)), ///
               ysc(r(., 11)) scheme(s1mono) leg(off)
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	21.5 KB
ID:	1645000

            Comment


            • #7
              Thank you, Andrew!

              Comment


              • #8
                Where are the numbers "
                scatteri 10.75 2 10.75 3, " from? People want to learn and never understand it.

                Comment


                • #9
                  Code:
                  scatteri 10.75 2 10.75 3, recast(line)
                  comes from looking at the graph and thinking that a straight line is needed between (10.75, 2) and (10.75, 3).

                  In #6 find the horizontal y = 10.75 and the vertical x = 2 and where they intersect as the point (10.75, 2) -- and so on.

                  A scatteri call without a recast() would give you individual points on a scatter plot. recast(line) converts two points to a line segment.

                  They are user choices, not results of other commands.

                  Comment


                  • #10
                    This code add bracket to the graph, however, the significance is still not available.

                    Comment


                    • #11
                      Indeed. You need extra code to write text on the graph. See

                      Code:
                      help added text options

                      Comment


                      • #12
                        Thank you! I really tried with the code below, however, the number didn't come out.
                        clear
                        sysuse pop2000, clear
                        replace maletotal = maletotal/1e+6
                        tw (bar maletotal agegrp in 1/5) (scatteri 10.55 2 10.55 3, recast(line) ///
                        lw(medthick) mc(none) lc(black) lp(solid)) (scatteri 10.55 2 10.55 3, ///
                        recast(dropline) base(10.52) lw(medthick) mc(none) lc(black) lp(solid)), ///
                        ysc(r(., 11)) scheme(s1mono) leg(off) ///
                        text(2.5 10.52 "6789", place(n))

                        Comment


                        • #13
                          You have the coordinates the wrong way round.

                          Comment


                          • #14
                            I am sorry that I really don't know how to add the texts above the flat line although I adjusted the coordinate to make the graph beautiful.

                            Comment


                            • #15
                              The text should be at 10.52 2.5 presumably not 2.5 10.52.

                              Comment

                              Working...
                              X