Announcement

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

  • Percentage bar graph

    Hi everybody,
    I would like to have a bar graph of the percentage of frequencies of several variables (serra estinz camcli smarif amrum iaria inqsu inqfiu disdr catastr fores2 inqelet2 paesag2 esriso2 altamb2), across 3 different regions (coded in the variable ripmf as 1, 2, 3)

    I manage to get the graph with frequencies which comes from the following code:

    graph bar (count) serra estinz camcli smarif amrum iaria inqsu inqfiu disdr catastr fores2 inqelet2 paesag2 esriso2 altamb2, over (ripmf)

    I tried the following code, but i get a weird output, that shows for each region (ripmf 1, 2, 3) the same value.

    graph bar (percent) serra estinz camcli smarif amrum iaria inqsu inqfiu disdr catastr fores2 inqelet2 paesag2 esriso2 altamb2, over (ripmf)

    how would you solve this?

    The graph i want would be like this one:




    Click image for larger version

Name:	Schermata 2023-07-21 alle 18.33.08.png
Views:	1
Size:	196.1 KB
ID:	1721400

  • #2
    Hi, Lisa.
    Can you share your data? Or give us an example? You can use -dataex-

    Code:
    ssc install dataex
    help dataex

    Comment


    • #3

      * Example generated by -dataex-. For more info, type help dataex
      clear
      input byte(serra estinz camcli smarif amrum iaria inqsu inqfiu disdr catastr fores2 inqelet2 paesag2 esriso2 altamb2 ripmf)
      1 . . 4 . 6 7 . . . . . 13 . . 1
      . 2 . . . . . 8 . 10 . 12 . . . 1
      . . . 4 5 . . . . . 11 . . . . 1
      . . 3 4 . . . . . . 11 . . . . 1
      . . . . . . . . 9 . . . . . . 1
      . . . . . . 7 . . . . . . . . 1
      . . 3 4 . 6 . . . . 11 . . . . 1
      . . 3 4 . 6 7 . . . 11 . . . . 1
      . . . . . . . . . . 11 . . . . 1
      . 2 3 . 5 . . . . . 11 . 13 . . 1
      . . . 4 . . . 8 . . 11 12 13 . . 1
      . . 3 . 5 6 7 8 . . . . . . . 1
      . . 3 . 5 6 7 8 . . . . . . . 1
      . . 3 4 5 6 7 . . . . . . . . 1
      . 2 . . . 6 7 8 . . 11 . . . . 1
      1 2 . 4 . . . . . . . . . . . 1
      . . 3 4 . 6 7 8 . . . . . . . 1
      1 . 3 . 5 6 7 . . . . . . . . 1
      1 2 3 . . 6 7 . . . . . . . . 1
      1 2 . 4 . . 7 8 . . . . . . . 1
      1 . 3 . . 6 7 8 . . . . . . . 1
      1 . 3 4 . 6 . 8 . . . . . . . 1
      1 2 3 . . 6 . 8 . . . . . . . 1
      . 2 3 . . . . 8 9 10 . . . . . 1
      1 . 3 4 . 6 . 8 . . . . . . . 1
      . 2 . . . . 7 8 . 10 11 . . . . 1
      . 2 . . . . . 8 . 10 11 . . . . 1
      1 . . . 5 . 7 . . . 11 . 13 . . 3
      1 2 3 . . . . . 9 . . 12 . . . 3
      . . 3 . . 6 . . 9 . 11 . . 14 . 3
      . . . . . . . 8 . . . . . . . 3
      . . . . . 6 7 8 . . . . . . . 3
      . . . . . . . 8 . . . . . . . 3
      . . . . . 6 7 8 . . . . . . . 3
      . . 3 . . 6 7 8 . . 11 . . . . 3
      . . 3 . . 6 7 8 . . 11 . . . . 3
      . . 3 . . 6 7 . . 10 . . 13 . . 3
      . . 3 . . 6 7 . . 10 . . 13 . . 3
      . . 3 . . 6 7 8 . . 11 . . . . 3
      . . 3 . . 6 7 8 . . . . . 14 . 3
      1 . . . 5 6 7 . . 10 . . . . . 3
      1 . . . . 6 . 8 9 10 . . . . . 3
      1 . . 4 . 6 7 . . 10 . . . . . 3
      1 . 3 4 . 6 . . . 10 . . . . . 3
      1 2 3 4 . 6 . . . . . . . . . 3
      1 2 3 4 . 6 . . . . . . . . . 3
      1 . . . . 6 . . . . . . . . . 3
      . . 3 . . 6 7 8 . . 11 . . . . 3
      . . . 4 . 6 . 8 . . . 12 . 14 . 3
      . . 3 4 . 6 . 8 . . . 12 . . . 3
      . . 3 4 . 6 . 8 . 10 . . . . . 3
      1 . 3 4 . 6 . . . . . . . 14 . 3
      1 . 3 4 . 6 . . . . . . . 14 . 3
      . . 3 . . 6 . 8 . . 11 . . 14 . 3
      1 . 3 . . . . 8 . 10 11 . . . . 3
      . . 3 4 . 6 . 8 . . . . . 14 . 3
      . 2 3 . . 6 7 8 . . . . . . . 3
      . . 3 . . 6 7 8 . . 11 . . . . 3
      1 . 3 . . 6 7 8 . . . . . . . 3
      . . 3 . 5 . . . 9 10 11 . . . . 3
      . . 3 . . . 7 8 . . . . 13 14 . 3
      1 2 3 4 5 . . . . . . . . . . 3
      . 2 3 . 5 6 . . . . . 12 . . . 3
      . . 3 4 . 6 7 8 . . . . . . . 3
      1 . 3 . . 6 . 8 . . 11 . . . . 3
      . . 3 . . . . . . . . . . . . 3
      . 2 3 4 . 6 7 . . . . . . . . 3
      . 2 3 4 . 6 7 . . . . . . . . 3
      . 2 3 4 . . 7 8 . . . . . . . 3
      . . . . . 6 . . . . . . . 14 . 3
      1 . 3 4 . 6 7 . . . . . . . . 3
      . . 3 4 . 6 . . . . . 12 13 . . 1
      . . 3 . . . 7 8 . 10 . . 13 . . 1
      . . . 4 . . 7 8 . 10 . . 13 . . 1
      . . 3 4 . . 7 . . . 11 . . . . 1
      . . . 4 . . 7 8 . . 11 . . . . 1
      . . 3 4 . . . . . . . . . . . 1
      . . 3 4 . . . . . . 11 . . . . 1
      . 2 3 4 . . 7 8 . . . . . . . 1
      1 . 3 . . . . . . . 11 . . . . 1
      . . . 4 . . 7 . . . 11 . 13 . . 1
      1 . 3 . . 6 . 8 . . 11 . . . . 1
      1 . 3 . . 6 . 8 . . 11 . . . . 1
      1 . . 4 . 6 . . . 10 . . 13 . . 1
      . 2 3 . . . . . 9 . 11 . . 14 . 1
      . . . 4 . . . 8 9 . . . 13 14 . 1
      . . 3 4 . . . . . . . . 13 . . 1
      1 2 3 . . . . . . . 11 12 . . . 1
      . 2 . 4 . 6 . 8 9 . . . . . . 1
      . 2 . . . 6 7 8 . . 11 . . . . 1
      . . 3 . . 6 7 8 . . 11 . . . . 1
      . . . . . . . . . . . . 13 . . 1
      1 2 3 4 5 . . . . . . . . . . 1
      . . 3 4 . . . . . . . . . . . 1
      1 . 3 4 . . . 8 9 . . . . . . 1
      . . . 4 . . 7 . 9 10 11 . . . . 1
      . . 3 4 . . . . . . . . 13 . . 1
      . . 3 4 . . . . . . . . 13 . . 1
      . . 3 4 . . 7 . . . 11 . . . . 1
      . . 3 4 . . 7 . . 10 . . . . . 1
      end
      label values ripmf label_ripmf
      label def label_ripmf 1 "North", modify
      label def label_ripmf 3 "South", modify
      [/CODE]

      So basically I have 15 variables that represent 15 environmental issues. People in the survey choose by crossing those that worry them the most. I want to visualize how these concerns spread across 3 italian regions: north, center and south, in percentage values.
      Last edited by Lisa Salvetti; 21 Jul 2023, 13:14.

      Comment


      • #4
        Code:
        clear all
        version 16.0
        
        sysuse nlsw88
        keep if inrange(occupation,1,5)
        
        generate byte w=1
        collapse (mean) wage (sum) w, by(race occu)
        
        frame copy default t
        drop w
        frame change t
        collapse (mean) wage [aw=w], by(occu)
        forval i=1/`=_N' {
        frame post default (9) (occu[`i']) (wage[`i'])
        }
        frame change default
        label define racelbl 9 "All", modify
        
        graph bar wage, ///
        over(race, label(angle(vertical)) ) ///
        over(occu, label(angle(vertical)) gap(300pct)) ///
        asyvar ///
        bar(1, color(ltblue)) ///
        bar(2, color(ebblue)) ///
        bar(3, color(gray)) ///
        blabel(bar , format(%6.2f) size(vsmall)) ///
        legend(pos(12) ring(0) bmargin(large) rows(1)) ///
        ytitle("Wage, USD") ///
        scale(0.5) xsize(16) ysize(9)
        Click image for larger version

Name:	statalist.png
Views:	1
Size:	81.2 KB
ID:	1721421

        Comment


        • #5
          my problem is just about percentages, and i would like to avoid generating15x3 new variables in order to do a graph

          Comment


          • #6
            certainly.

            Code:
            graph bar (percent) serra estinz camcli smarif amrum iaria inqsu inqfiu disdr catastr fores2 inqelet2 paesag2 esriso2 altamb2, over (ripmf) blabel(bar, format(%6.2f)) scale(0.5)  legend(cols(4)) ytitle(percent)

            Click image for larger version

Name:	statalist2.png
Views:	1
Size:	80.7 KB
ID:	1721430

            Comment

            Working...
            X