Announcement

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

  • Graphing more than 1 variable in cibar (is this possible?)

    Greetings,

    I'm running Stata 15.1 on OSX. I've recently installed the cibar package as other methods for generating bar graphs with confidence intervals seemed too laborious. However, cibar appears to only allow you to graph a single variable. If I try to include more than one, only the first in the series is graphed. Is there an option I'm missing here or is this merely the limitation of using cibar? Thanks for your help!

  • #2
    cibar is from SSC. Its declared syntax is just

    cibar varname [if], over1(varname) [options]
    so using it to get confidence intervals for several variables would require a change of data structure so that different variables become distinct groups of observations. You're right that it allows but ignores variables other than the first-named. For why, you'd need to ask the author.

    Although it's been abandoned by its author, ciplot (SSC) supports multiple variables. It even supports, by accident rather than design, the awful dynamite/detonator/plunger plot style:


    Code:
    sysuse auto, clear
    ciplot turn trunk
    ciplot turn trunk, recast(bar) bfcolor(none ..) base(0)
    It's usually better to show much more than means and their CIs.
    Last edited by Nick Cox; 22 May 2019, 01:02.

    Comment


    • #3
      Hey Nick,

      This is very helpful. Is it possible to also have the percentages/figures labeled above each bar as is done with the blabel() command in 'graph bar'?

      -Zach

      Comment


      • #4
        Which percentages or figures would that be? With two or more variables the number of observations used will by default be the same for all variables -- precisely those observations for which all variables plotted have non-missing values.

        Comment


        • #5
          Hey Nick,

          Here's some sample data to better illustrate what I mean

          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input byte(courtesy disrespect) float hispanic
          1 1 0
          2 2 0
          4 3 0
          3 3 1
          4 3 1
          3 3 0
          2 4 1
          3 3 1
          2 2 1
          4 4 1
          2 2 1
          1 1 1
          1 1 1
          1 1 1
          2 2 1
          1 1 0
          2 2 0
          1 1 1
          1 1 1
          4 2 1
          3 3 1
          2 2 1
          2 3 1
          3 2 1
          3 3 0
          2 2 0
          1 1 0
          1 1 0
          3 3 1
          2 1 1
          1 1 0
          3 3 0
          1 1 0
          4 4 1
          3 3 1
          1 1 1
          3 3 1
          2 2 1
          3 3 0
          6 3 0
          3 3 0
          2 2 1
          4 4 1
          2 2 1
          3 5 1
          2 2 1
          4 2 0
          1 1 0
          4 4 1
          2 5 0
          3 3 1
          2 2 1
          4 4 1
          1 1 1
          5 5 1
          2 2 0
          1 1 1
          1 1 1
          4 3 1
          1 1 1
          5 2 1
          1 1 1
          1 2 1
          1 1 1
          2 2 0
          3 2 1
          1 1 1
          1 1 1
          3 1 1
          1 1 1
          1 1 1
          1 1 0
          3 3 0
          1 1 1
          1 1 1
          1 1 1
          5 5 1
          3 2 1
          1 1 1
          1 1 1
          3 3 0
          1 1 0
          1 1 1
          1 1 1
          2 3 1
          3 1 1
          5 4 1
          1 1 1
          2 1 1
          1 1 1
          4 4 1
          4 4 1
          1 1 1
          3 2 1
          5 5 1
          2 1 1
          1 1 1
          2 2 1
          1 1 1
          1 1 1
          end
          label values courtesy revV06538
          label def revV06538 1 "(IF VOL) NEVER", modify
          label def revV06538 2 "LESS THAN ONCE A YEAR", modify
          label def revV06538 3 "A FEW TIMES A YEAR", modify
          label def revV06538 4 "A FEW TIMES A MONTH", modify
          label def revV06538 5 "AT LEAST ONCE A WEEK", modify
          label def revV06538 6 "ALMOST EVERYDAY", modify
          label values disrespect revV06539
          label def revV06539 1 "(IF VOL) NEVER", modify
          label def revV06539 2 "LESS THAN ONCE A YEAR", modify
          label def revV06539 3 "A FEW TIMES A YEAR", modify
          label def revV06539 4 "A FEW TIMES A MONTH", modify
          label def revV06539 5 "AT LEAST ONCE A WEEK", modify
          The variables here are ordinal. Thus, in addition to the rcap, I wanted to know if it's possible to have the mean for each 'over' group (in the above, hispanic or non-hispanic) labeled above the bars. Thanks again!

          Comment


          • #6
            By mean for each over group I'm referring to the groups means on the y variable (not the number of observations per group)

            Comment


            • #7
              That's not wired in. As perhaps implied in the help, ciplot is not a command I have interest in extending as I believe that there is much more flexibility in other approaches. I will be away from my computers for a while, but if you don't get another better answer I will try to look at this next week.

              Comment


              • #8
                Got it. What's the easiest approach you'd recommend (you can just link me to the relevant thread if you don't feel like elaborating)?

                Comment


                • #9
                  The help for ciplot (SSC) points to my paper on "The statsby strategy" (now accessible at https://journals.sagepub.com/doi/pdf...867X1001000112) which is a natural here.


                  With your dataset example, I proceed (and naturally all kinds of different small choices are possible):

                  Code:
                  save tokendata, replace 
                  
                  statsby , by(hispanic) : ci means courtesy
                  gen which = "courtesy" 
                  save ciresults, replace 
                  
                  u tokendata 
                  statsby , by(hispanic) : ci means disrespect 
                  gen which = "disrespect" 
                  append using ciresults 
                  
                  encode which, gen(Which) 
                  
                  gen toshow = string(mean, "%3.2f") 
                  gen yshow = 2.9 
                  
                  set scheme s1mono 
                  twoway scatter mean hispanic, xsc(r(-0.2 1.2)) yla(, ang(h)) ///
                  || scatter yshow hispanic, ms(none) mlabpos(0) mlabsize(medium) mla(toshow) ///
                  || rcap ub lb hispanic , by(which, note("") legend(off)) xla(0 "no" 1 "yes")

                  Click image for larger version

Name:	ci_results.png
Views:	1
Size:	16.8 KB
ID:	1500156

                  Comment

                  Working...
                  X