Announcement

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

  • Changing the positions in a bar chart

    Hi everyone,
    I would appreciate some help by designing my bar graphs! I have the following datatset
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int ID_1 byte Ability_homogen float Performance1_total4 double Performance2_total
    201 0 122 244
    202 0 135 147
    203 1 223 175
    204 1 208 192
    205 1 131 105
    207 0 233 190
    208 1  89  90
    209 0 180 161
    210 0 228 146
    211 0 267 357
    212 0 153 190
    213 1 255 155
    214 0 194 240
    215 0 228 272
    216 0 216 293
    217 0 207 204
    218 0 223 219
    219 1 145 169
    220 0 167 132
    221 1 130 168
    222 0 164 189
    223 0 174 228
    224 1  96  89
    225 0 148 189
    end

    and want to get a bar graph which displays in 2 seperate areas of the graph Performance1_total for both types of Ability_homogen and in the other area of the graph two bars for Performance2_total with both types of Ability_total
    I tried with:
    graph bar Performance1_total4 Performance2_total, by(Ability_homogen),
    but my goal is not to have two charts, one for Ability_homogen=0 an one for Ability_homogen=1, but for Performance1_total4 and Performance2_total.

    Thanks a lot!




  • #2
    See statplot from SSC.

    Code:
    statplot Performance*, over(Ability) recast(bar)
    may be closer to what you want.

    Comment


    • #3
      Awesome, thank you so much Nick!!

      Comment


      • #4
        Hey Nick,

        maybe you can help me once again? In a different dateset I have 3 different groups (Treatment==0; Treatment==1&Performance_div==0 and Treatment==1&Performance_div==1). How can I graph those in a barchart such that I have the bars grouped over those 3 on the x-axis (instead of 2 groups like before) and the Performance Variable is my y-axis?

        Thanks a lot!

        Comment


        • #5
          Data example and code you've tried so far, please.

          Comment


          • #6
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input int ID_1 float Treatment byte Performance1_total4_div float Performance1_total4
              1 0 . 171
              2 0 . 251
              3 0 .  97
              4 0 .  99
              5 0 . 145
              6 0 .  90
              9 0 .  99
             11 0 . 138
             14 0 . 140
             15 0 . 103
             16 0 .  72
             17 0 .  91
             18 0 .  53
             24 0 . 146
             28 0 .  86
             31 0 . 113
             32 0 . 104
             33 0 . 136
             36 0 .  60
             37 0 . 132
             38 0 .  73
             44 0 .  43
             46 0 . 304
             47 0 .  80
             51 0 . 193
             52 0 . 167
             53 0 . 185
             54 0 . 117
             58 0 .  30
             60 0 . 131
             61 0 . 135
             63 0 . 146
             65 0 . 149
             66 0 .  85
             67 0 . 127
             68 0 .  96
             69 0 . 119
             70 0 . 203
             72 0 . 130
             73 0 .  66
             74 0 .  81
             75 0 .  46
             76 0 .  95
             78 0 .  42
             79 0 .  78
             84 0 . 135
             85 0 .  70
             87 0 .  97
             88 0 . 151
             89 0 . 109
             91 0 . 149
             94 0 .  34
             95 0 . 194
             97 0 . 177
             98 0 .  51
             99 0 . 171
            101 0 . 137
            104 0 . 102
            201 1 0 122
            202 1 0 135
            203 1 1 223
            204 1 1 208
            205 1 0 131
            207 1 1 233
            208 1 0  89
            209 1 1 180
            210 1 1 228
            211 1 1 267
            212 1 0 153
            213 1 1 255
            214 1 1 194
            215 1 1 228
            216 1 1 216
            217 1 1 207
            218 1 1 223
            219 1 0 145
            220 1 0 167
            221 1 0 130
            222 1 0 164
            223 1 0 174
            224 1 0  96
            225 1 0 148
            end

            The Treatment-group is also now divided in Performance1_total4_div==0 or ==1.
            I have tried the following:
            statplot Performance1_total4, over(Treatment) over(Performance1_total4_div) recast(bar)
            or
            twoway bar Performance1_total4 Treatment || bar Performance1_total4 Treatment==1 & Performance1_total4_div==0|| bar Performance1_total4 if Treatment==1 & Performance1_total4_div==1


            Thank you!

            Comment


            • #7
              I guess the major problem here is that the missing values should be recoded, say to 2, and then you have 3 non-missing categories.

              Comment


              • #8
                See also https://www.statalist.org/forums/for...rent-variables in which the focus is on plotting 3 means and one suggestion is that you have space and scope to be much more interesting and informative.

                Comment

                Working...
                X