Announcement

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

  • A simple graph bar

    Dear Statalist,

    Unfortunately, I need to bother you because of a simple bar graph. I am a rookie concerning Stata and can't fix the problem by myself.
    I tried to work it out for hours but without any good solution.
    Here is what I want to do:
    I asked in a survey individuals whether they know a certain German law (simple yes/no question). The participants are grouped into treatment and a control group. Now, I want a bar graph which displays the percentage of participants who answered the question with yes or no according to their group membership. That means, I want a graph with four bars (yes(treatment), yes(controls); no(treatments, no(controls). My problem is, that I can get either a graph which looks the way I like but with wrong percentages or a graph with correct percentages but it doesn't look the way I like.

    To give you an example:
    Click image for larger version

Name:	graph1.PNG
Views:	1
Size:	9.2 KB
ID:	1348986


    My graph should look like this, but in this graph the percentage are wrong (e.g. 84% of the treatments answered the question with yes).
    I want that each bar displays not the total percentages, but the percentage of each subgroup.


    Click image for larger version

Name:	graph2.PNG
Views:	1
Size:	10.1 KB
ID:	1348987


    In this graph, I have the correct percentages for each subgroup. But I would prefer, if the two "yes-bars" and "no-bars" would be together, so that it would be easy to compare them.

    Is there a way how I can achieve this? I would be so grateful if you can give me a small example how I can work it out.
    In normal circumstances I would try it by myself till I have worked it out, but the deadline for my master thesis is very soon.....

    Greetings
    Fabian

  • #2
    Welcome to Statalist!

    We can better help you if we know what commands you have tried that produced your output. Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. See especially sections 9-12 on how to best pose your question. It's particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using CODE delimiters, as described in section 12 of the FAQ.

    Comment


    • #3
      William gives excellent advice as always. (Urgency we have sympathy with, but it's not infectious.)

      In addition I posted yesterday in this thread

      http://www.statalist.org/forums/foru...tplot-to-graph

      about plotting percent yes or not given 2 x 2 controls, which appears to be exactly the problem here.

      Comment


      • #4
        Hey. First, I want to thank you both for your fast reply and help. I am new in this forum and I am not yet used to it. So I want to apologize to you both for my not really well stated question. I am trying to improve =) I tried to install dataex, but it did not work. I guess it can be because of my university license, but I am not sure.
        However, I was able to produce a graph what comes close to the graph I want.
        Click image for larger version

Name:	graph5.PNG
Views:	1
Size:	9.2 KB
ID:	1349079



        I used following code to produce it:
        Code:
        graph bar, over(alcbanBW) over(treatment) percentages cw name(bar1, replace) ytitle(percent)  asy
        Click image for larger version

Name:	tab1.PNG
Views:	1
Size:	8.2 KB
ID:	1349080




        The graph displays the correct values. However, I would be really happy if the two "yes"-bars would be together and the two "no"bars. If this is not possible, I would take my graph like that.

        Nick Cox : Your example comes close to what I want. However, there shouldn't be a dependent variable. But I really want to thank you for all your effort you are investing in this forum.


        I know, that the presentation of my problem is once again not really good. I am sorry for that.

        Greetings
        Fabian

        Last edited by Fabian Bunzel; 12 Jul 2016, 13:57.

        Comment


        • #5
          I think you just need to change the order of your over() calls.

          Code:
          graph bar, over(alcbanBW) over(treatment) percentages cw name(bar1, replace) ytitle(percent)  asy

          Comment

          Working...
          X