Announcement

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

  • Likert-scale graph

    Hello everybody,

    I have a question regarding the graph for a likert scale variable (the likert scale has 5 categories). I'd like to create a graph similarly like this one:
    Click image for larger version

Name:	Grafik.png
Views:	1
Size:	28.5 KB
ID:	1378812


    If anybody has an idea, or an example code that shows how I can create such a nice bar chart, I would be very happy (I already tried, the catplot and the slideplot command). The categories "Strongly agre" etc. can be shown in a legend.

    Thank you


  • #2
    Something along these lines:
    Code:
    clear *
    set more off
    input str50 cat byte pct
    "Strongly Disagree" 10
    "Disagree" 15
    "Neutral" 0
    "Agree" 30
    "Strongly Agree" 45
    end
    
    label define Categories 0 "Strongly Disagree" 1 Disagree 2 Neutral 3 Agree 4 "Strongly Agree"
    encode cat, generate(Cat) label(Categories) noextend
    
    *
    * Begin here
    *
    graph hbar (asis) pct, over(Cat) asyvar stack

    Comment


    • #3
      Thank you very much for your help.

      I managed to create this graph before with the sideplot command
      Code:
      slideplot hbar F101_10, pos(1 2 3 4 5) neg(0)
      bar(1, bcolor(blue*0.4)) ///
      bar(2, bcolor(blue*0.8)) ///
      bar(3, bcolor(red*0.2))  ///
      bar(4, bcolor(red*0.6))  ///
      bar(5, bcolor(red)) legend(row(1)) percent
      I prefer your solution. But whats missing is the visual display of the percent value in the bars. Any idea how I can make it to appear? I saw an example in Excel, but I think if Excel can create such a bar, there must be a solution in stata?
      And the bar is slighty bold, how can I change that?

      Thanks in andvace!
      Last edited by Mia Blumer; 17 Mar 2017, 01:59.

      Comment


      • #4
        I tried to create something with your Code above
        #2
        Code:
        clear
        set more off
        input str50 cat F
        "Stimme überhaut nicht zu" 6
        "2" 28
        "3" 68
        "4" 149
        "Stimme voll zu" 255
        end
        
        label define Categories 0 "Stimme überhaut nicht zu" 1 "2" 2 "3" 3 "4" 4 "Stimme voll zu"
        encode cat, generate(Cat) label(Categories) noextend
        
        graph hbar F, over(Cat) asyvar stack blabel(bar, format(%3.2f)) ytitle(Prozent)
        With the extend
        blabel(bar, format(%3.2f)) ytitle(Prozent)
        the frequencies values are written in the bar.

        But I would like to have percent values and not the absolut values in the chart (x-axis = 100 %) Any Idea?

        Thank you

        Comment


        • #5
          I think the answer is to calculate the percentages yourself and then plot the percentages.
          Code:
          egen Ftot = total(F)
          generate Fpct = F/Ftot
          graph hbar Fpct, ...
          I note also that slideplot accepts the same graph options as graph hbar, so you might try adding the blabel option to that command to see if it will visually display the values in the bars.
          Last edited by William Lisowski; 17 Mar 2017, 06:16.

          Comment


          • #6
            Just to ride a hobby-horse, which will be familiar to many here, from unflagging repetition, but the example illustrates all too well a disadvantage of the stacked design, which is highly popular but deeply flawed (a factor underlying my reluctance to rewrite slideplot (which should be explained here as a user-written program from SSC (do please read the FAQ Advice))).

            A reader has to look and think twice to notice that the neutral category is 0%, detectable only by its absence.

            Otherwise put, the bar of zero length exists in principle but it is really hard to spot except with theological skill.

            Also, let's be generous and suppose that it might have been 1%. You still don't have very much space to superimpose the text.

            For an alternative, search the forum (or indeed Stata) for recent mentions of tabplot (Stata Journal).
            Last edited by Nick Cox; 17 Mar 2017, 06:58.

            Comment


            • #7
              Thank you William

              Now the Code looks like:
              Code:
              clear
              set more off
              input str50 cat F
              "Stimme überhaut nicht zu" 6
              "2" 28
              "3" 68
              "4" 149
              "Stimme voll zu" 255
              end
              
              label define Categories 0 "Stimme überhaut nicht zu" 1 "2" 2 "3" 3 "4" 4 "Stimme voll zu"
              encode cat, generate(Cat) label(Categories) noextend
              
              egen  Ftot = total(F)
              generate  Fpct =  F/ Ftot
              
              graph hbar Fpct, over(Cat)asyvar stack blabel(bar, format(%3.2f)) ytitle(Prozent)
              And the result looks like the one in the attachment. Click image for larger version

Name:	Grafik_1.png
Views:	1
Size:	36.8 KB
ID:	1378896

              Almost there.
              The x-Axis is still not expressed as a percentage, also the percent values (which are still not percent values) are displayed one to far right. For example the red one (1%) should be in the blue one, the green one (6%) should be in the red one etc.
              Any Idea to fix this? I can't belive that there is not a simple Code for this kind of graph?

              Thank you very much for your advice!
              Last edited by Mia Blumer; 17 Mar 2017, 07:06.

              Comment


              • #8
                Thank you for the answer Nick

                I already tried tabplot command:
                Code:
                slideplot hbar F101_10, pos(1 2 3 4 5) neg(0)
                bar(Strongly Disagree, bcolor(blue*0.4)) ///
                bar(2, bcolor(blue*0.8)) ///
                bar(3, bcolor(red*0.2))  ///
                bar(4, bcolor(red*0.6))  ///
                bar(agree, bcolor(red)) legend(row(1)) percent
                
                tabplot F101_10, percent(F101_10) horizontal ///
                showval(offset(0.05) mlabsize(*1.1) mlabcolor(black)) ///
                bfcolor(none) height(0.7) xsc(r(0.8 .))
                blabel(bar, position(center) format(%12.1f) color(white)
                Result: Click image for larger version

Name:	grafik_2.png
Views:	1
Size:	25.5 KB
ID:	1378901

                Therefore I went with the solution provided by Joseph and Willam. Its almost what I invisioned.

                Comment


                • #9
                  Responding to post #7 above:

                  The x-Axis is still not expressed as a percentage, also the percent values (which are still not percent values) ...
                  We see that you copied the code I provided in post #5, which clearly divides the individual values by their total, which will of course give a fraction between 0 and 1. To convert such a fraction to a percentage, you multiply by 100. But you will still be disappointed in that there is, to the best of my knowledge, no numeric format in Stata that displays a number followed by a percentage sign.

                  the percent values ... are displayed one to far right.
                  In help hbar find the blabel option and click on it to take you to a description of the use of the blabel option, where you will see that there are sub-options that control the positioning of the label. In your code in post #7 you will want
                  Code:
                  blabel(bar, format(%3.2f) position(center))

                  I can't belive that there is not a simple Code for this kind of graph?
                  I very much can, and this is at the heart of your misunderstanding of Stata. The two answers above suggest that in this case you are not interested in understanding how Stata produces graphs and learning how to use those tools, but rather in finding a tool to create your plot easily. There is nothing wrong with that, but Stata is not and will not be such a tool.

                  Stata's market is in general the preparation of scientific analyses. The "sidebar" plot (to give it a name) is not commonly used to present science to scientists. As Nick correctly explains, it has numerous potential and practical problems. The only presentation of sidebar plots I recall seeing in scientific literature is in articles that present them to call attention to their deficits, That is not to say sidebar plots are not useful. I see them often in PowerPoint presentations by presenters who need bright colors and big pictures to hold their audience's attention in a way that a table of four or five numbers (because really, that is all that this chart presents) would not, when projected on a large screen in a darkened room.

                  With that said, I see no reason for StataCorp to make it easy to create sidebar plots within Stata when they have already made it easy to export Stata data to Excel to easily create sidebar plots. I often export my data to Excel when I need to do something that I know how to do easily in Excel (and am too hurried or lazy to see if it can easily done in Stata). This is particularly the case when I want to do something that people are familiar to seeing produced by Excel. Pivot tables and charts derived from them are for me the prime example of that use. In the time it might take me in Stata to summarize my data suitably and begin looking up the graph commands and their options and the options to their options, ... I can be in and out of Excel with my work done.

                  Given the limited resources that StataCorp has, I think they are best devoted to providing those features - deeply technical statistical techniques - that are not already met by other sources, and to making it easy to move Stata data into tools, like Excel, that can extend Stata's capabilities in other directions.

                  So the lesson is, I think, to choose the appropriate tool for the job. Excel is the appropriate source of simply produced sidebar plots.
                  Last edited by William Lisowski; 17 Mar 2017, 08:52.

                  Comment

                  Working...
                  X