Announcement

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

  • Bar Chart with three Variables and five categories in one graph

    Hello everybody

    I am trying to generate a bar chart where I have three different variables on the X-Axis (Var1 to Var3) and the mean on the Y axis (scaled from 1 to 5).
    I am able to create for each variable (A104_01, A104_03 and A104_05) the corresponding graphs. For example the three graphs are:

    label define label_A104 1 "XX" 2 "YY" 3 "ZZ" 4 "VV" 5 "UU"
    label values A104_* label_A104
    graph bar, over(A104_01) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
    graph bar, over(A104_03) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
    graph bar, over(A104_05) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))

    But how can i combine these three in one graph, that it should looks like:


    ⎪⎪
    ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪
    ⎪⎪ ⎪⎪ ⎪⎪

    V1 V2 V3 ; V1 V2 V3 ; V1 V2 V3 ; V1 V2 V3 ; V1 V2 V3 ;

    I hope you understand my problem, looking foreward to answers!
    Thank you very much!



  • #2
    Code:
    clear 
    set obs 100 
    egen whatever = seq(), block(20) 
    set seed 2803 
    forval j = 1/3 { 
        gen v`j' = `j' * runiform()
    } 
    
    graph bar (mean) v1 v2 v3, over(whatever)

    Comment


    • #3
      Thank you very much for the quick anwer!
      But now stata gives my the error that there is "variable A104_01 not found" etc., although i labeled and defined it.

      Comment


      • #4
        We can't see your dataset. Nor can we tell what's wrong with code you don't show us. Please show us

        1. the complete bar chart command you typed


        2. the result of

        Code:
        ds
        Review of http://www.statalist.org/forums/help#stata might also help.

        Comment


        • #5
          1. Code:
          clear
          set obs 100
          egen A104_1 = seq(), block(20)
          label define label_A104 1 "unwichtig" 2 "nicht so wichtig" 3 "neutral" 4 "wichti g" 5 "sehr wichtig"
          label values A104_* label_A104
          set seed 2803
          forval j = 1/3 {
          gen v`j' = `j' * runiform() }

          graph bar (mean) A104_01 A104_03 A104_05, over(A104_1)

          2. Error: "variable A104_01 not found"


          but when I run the graph separately, stata shows the graphs:

          Code:
          label define label_A104 1 "unwichtig" 2 "nicht so wichtig" 3 "neutral" 4 "wichti g" 5 "sehr wichtig"
          label values A104_* label_A104
          graph bar, over(A104_01) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
          graph bar, over(A104_03) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
          graph bar, over(A104_05) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))

          Comment


          • #6
            You didn't answer my request 2 in #4 but I can work out what is wrong.

            Stata is right. You created A104_1 but there is no A104_01 in your data. There is no A104_03 or A104_05 either.

            Back-tracking: I gave you a self-contained and complete code example that can be run. I did that because, despite the advice given in http://www.statalist.org/forums/help#stata, you did not provide a data example yourself. That code example starts with clear. It is important to read the help for clear and realise what it does: clear the present data.

            Your code mushes together your original code for your data and my code based on a different dataset the code creates. That won't work.

            This is legal:

            Code:
            graph bar (mean) A104_01 A104_03 A104_05, over(A104_1)
            but if and only if you have all those variables named in the command as part of your dataset and the first three are numeric variables.

            Comment


            • #7
              Thank you
              Problem ist that I have three variables A104_01, A104_03 and A104_05, which all have the categories 1, 2, 3, 4, 5. To create the graphs separately I use the Code:
              label define label_A104 1 "unwichtig" 2 "nicht so wichtig" 3 "neutral" 4 "wichti g" 5 "sehr wichtig"
              label values A104_* label_A104
              graph bar, over(A104_01) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
              graph bar, over(A104_03) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
              graph bar, over(A104_05) blabel(bar, format(%3.2f)) ytitle(Prozent) legend(size(small))
              alll works fine.

              Now I intend to show this three variables in one graph.
              I used the Code:
              graph bar (mean) A104_01, A104_03 A104_05
              but there are just three bars, so thats not the way to go. For the the five categories I tried
              graph bar (mean) A104_01 A104_03 over (A104_05)
              There is the chart I wanted with the 5 categories and the variables, but just variable A104_01 A104_03 are shown in the graph and A104_05 is missing. And because the following Code does not function
              graph bar (mean) A104_01 A104_03 A104_05, over (A104_05)
              I assume that I have to generate a new variable?
              So the question is do i have to generate a new variable "XX" for
              graph bar (mean) A104_01 A104_03 A104_05, over (XX)
              , for example
              gen XX = A104_05,
              and then the Code is
              graph bar (mean) A104_01 A104_03 A104_05, over (XX)
              . But is the new variable XX right? or do I have to generate a new variable out of all three variables? And How could this variable "XX" look like?

              Thank you
              Last edited by Mia Blumer; 06 Mar 2017, 23:44.

              Comment


              • #8
                I am lost here in the absence of a data example. It's fundamental: we can't see your data and if you don't explain it with total clarity we are lost.

                You have now been asked to read the FAQ Advice before posting: whenever you looked at the Statalist home page, every time you post something new, and explicitly twice by me in #4 and #6 of this thread.

                Let me ask one more time: please read

                http://www.statalist.org/forums/help#stata and then install dataex (SSC) and then post a data example.

                Comment


                • #9
                  will ask a friend to help me. Nevertheless thank you very much trying to help.

                  Comment


                  • #10
                    If your friend can't solve it I remain willing to help. I just need a clear question.

                    Comment

                    Working...
                    X