Announcement

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

  • Bar graph binary variables


    Hi guys I am new to this forum and wanted to ask if someone can help me with my problem. I need to visualise data using a bar chart it is mostly binary variables. And I need to visualise the data in a bar chart, I can already visualise the data in several bar charts successfully but I need to visualise it in one and it doesn't work somehow. Maybe one of you can help me. Please I have the first two graphs and I have no idea how to bring them together as in graph 3.
    Click image for larger version

Name:	Graph 1.PNG
Views:	2
Size:	30.1 KB
ID:	1733065
    Click image for larger version

Name:	Graph 2.PNG
Views:	2
Size:	19.7 KB
ID:	1733066
    Click image for larger version

Name:	Graph3.PNG
Views:	2
Size:	32.5 KB
ID:	1733067

  • #2
    These are the code for my two grafiks.

    statplot choice1 choice2 choice3, over(starting_role, sort(1)) recast(bar)

    statplot Groupchoice1 Groupchoice2 Groupchoice3,recast(bar)

    Comment


    • #3
      statplot is from SSC. I am familiar with it as one of its authors but I am puzzled by your questions as it doesn't support error bars, confidence intervals or similar uncertainty intervals.

      There isn't a data example here and it's not clear whether your choice1 choice2 choice3 are really the same as the other Groupchoice* variables mentioned.

      I am taking it that you have 3 binary variables that are 0 and 1 and another variable that takes on 3 values.

      Here is a script that shows some technique. I guess that choice1 choice2 choice3 should be used not c_city south collgrad and starting_role not race

      In suggesting code I am mindful of strong advice against so-called dynamite plots, detonator plots, or plunger plots, as often mentioned here. See e.g.

      https://biostat.app.vumc.org/wiki/pu...de/Poster3.pdf

      https://simplystatistics.org/posts/2...lots-must-die/

      Should someone with power over you be insisting on such plots, even after reading advice such as the above, then you need
      twoway bar not scatter

      Code:
      webuse nlswork, clear 
      
      local j = 1 
      foreach v in c_city south collgrad { 
          local label : var label `v'
          preserve 
          statsby, by(race) : ci proportion `v'
          gen varname = "`v'"
          gen label = "`label'"
          save ci_`j', replace 
          local ++j 
          restore 
      }
      
      clear 
      append using ci_1 ci_2 ci_3 
      
      list 
      
      dataex 
      
      replace label = varname if missing(label)
      
      scatter mean race , by(label, row(1) note("") legend(off)) xla(1/3, valuelabel) ytitle(Mean proportion and 95% confidence interval) || rcap ub lb race

      Code:
       webuse nlswork, clear 
      (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
      
      . 
      . local j = 1 
      
      . foreach v in c_city south collgrad { 
        2.         local label : var label `v'
        3.         preserve 
        4.         statsby, by(race) : ci proportion `v'
        5.         gen varname = "`v'"
        6.         gen label = "`label'"
        7.         save ci_`j', replace 
        8.         local ++j 
        9.         restore 
       10. }
      (running ci on estimation sample)
      
            Command: ci proportion c_city
               mean: r(mean)
                  N: r(N)
         proportion: r(proportion)
                 se: r(se)
                 lb: r(lb)
                 ub: r(ub)
              level: r(level)
                 By: race
      
      Statsby groups:
      ...
      file ci_1.dta saved
      (running ci on estimation sample)
      
            Command: ci proportion south
               mean: r(mean)
                  N: r(N)
         proportion: r(proportion)
                 se: r(se)
                 lb: r(lb)
                 ub: r(ub)
              level: r(level)
                 By: race
      
      Statsby groups:
      ...
      file ci_2.dta saved
      (running ci on estimation sample)
      
            Command: ci proportion collgrad
               mean: r(mean)
                  N: r(N)
         proportion: r(proportion)
                 se: r(se)
                 lb: r(lb)
                 ub: r(ub)
              level: r(level)
                 By: race
      
      Statsby groups:
      ...
      file ci_3.dta saved
      
      . 
      . clear 
      
      . append using ci_1 ci_2 ci_3 
      (label racelbl already defined)
      (variable varname was str6, now str8 to accommodate using data's values)
      (variable label was str17, now str21 to accommodate using data's values)
      (label racelbl already defined)
      
      . 
      . list 
      
           +-----------------------------------------------------------------------------------------------------------------+
           |  race       mean       N   propor~n         se         lb         ub   level    varname                   label |
           |-----------------------------------------------------------------------------------------------------------------|
        1. | White   .2720333   20174   .2720333   .0031331    .265901   .2782314      95     c_city       1 if central city |
        2. | Black   .5710026    8049   .5710026   .0055166    .560104   .5818498      95     c_city       1 if central city |
        3. | Other    .349835     303    .349835   .0273982   .2961884    .406451      95     c_city       1 if central city |
        4. | White    .328046   20174    .328046   .0033055   .3215677   .3345739      95      south              1 if south |
        5. | Black   .6247981    8049   .6247981   .0053967   .6141149   .6353909      95      south              1 if south |
           |-----------------------------------------------------------------------------------------------------------------|
        6. | Other   .1188119     303   .1188119   .0185884   .0846178   .1606762      95      south              1 if south |
        7. | White   .1906838   20180   .1906838   .0027654   .1852839   .1961731      95   collgrad   1 if college graduate |
        8. | Black   .1074401    8051   .1074401   .0034513   .1007566   .1144092      95   collgrad   1 if college graduate |
        9. | Other   .2706271     303   .2706271   .0255234   .2214126   .3243896      95   collgrad   1 if college graduate |
           +-----------------------------------------------------------------------------------------------------------------+
      
      . 
      . dataex 
      
      ----------------------- copy starting from the next line -----------------------
      <edited to below> 
      ------------------ copy up to and including the previous line ------------------
      
      Listed 9 out of 9 observations
      
      . 
      . replace label = varname if missing(label)
      (0 real changes made)
      
      . 
      . scatter mean race , by(label, row(1) note("") legend(off)) xla(1/3, valuelabel) ytitle(Mean proportion and 95% confidence interval) ||
      >  rcap ub lb race
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte race float(mean N proportion se lb ub level) str8 varname str21 label
      1  .2720333 20174  .2720333 .003133075   .265901 .27823135 95 "c_city"   "1 if central city"    
      2  .5710026  8049  .5710026  .00551665 .56010395  .5818498 95 "c_city"   "1 if central city"    
      3   .349835   303   .349835 .027398204 .29618835   .406451 95 "c_city"   "1 if central city"    
      1   .328046 20174   .328046  .00330553 .32156765  .3345739 95 "south"    "1 if south"           
      2  .6247981  8049  .6247981 .005396739  .6141149  .6353909 95 "south"    "1 if south"           
      3 .11881188   303 .11881188  .01858844  .0846178 .16067624 95 "south"    "1 if south"           
      1 .19068384 20180 .19068384 .002765384 .18528387  .1961731 95 "collgrad" "1 if college graduate"
      2 .10744007  8051 .10744007 .003451254  .1007566 .11440916 95 "collgrad" "1 if college graduate"
      3 .27062705   303 .27062705 .025523435 .22141264  .3243896 95 "collgrad" "1 if college graduate"
      end
      label values race racelbl
      label def racelbl 1 "White", modify
      label def racelbl 2 "Black", modify
      label def racelbl 3 "Other", modify
      Click image for larger version

Name:	notadetonator.png
Views:	1
Size:	48.2 KB
ID:	1733162

      Comment


      • #4
        all 2 sessions.dta

        Thanks for your answer, I have now also attached the dataset and there it is: I have 2 sessions. Each session consists of 24 participants and there are always three together in groups. In a group there are always 2 people with the starting role 1 type A and one with the starting role 0 type B (like the graphic above) and I would like to know how to make a bar chart like this and also a scatter plot like what you suggested. groupchoice (groupchoice1,2,3) would be if 2 people in a group voted for 1, the whole group is 1 and if two people voted for 0, the group is 0 and groupchoice should be the value of how many groups voted for 1. choice1=winner takes all choice2 = steep choice3= balanced. Can you help me with the exact example please Best Alex

        Comment


        • #5
          Sorry, but you're asked not to post .dta attachments. Please read the FAQ Advice carefully.

          https://www.statalist.org/forums/help

          especially #12 in the above.

          You got some very detailed help in #3 and you're expected (by me, and typically by others active here in similar roles) at least to try to adapt the code. In any case, sorry, but I have meetings for some hours now so that alone rules out hand-holding.

          Comment


          • #6
            I'm sorry it was my mistake, but thanks for your help

            Comment

            Working...
            X