Announcement

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

  • Graph bar

    Goodmorning,
    I have the following dataset were percent1 percent2 perecent3 are the perecentage of individual (divided in 3 different group) that belong to a specific occupation which can range between 1 and 9

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(percent1 percent2 percent3 occupation_name)
    .15052333 . . 6
    .15052333 . . 6
    .07870075 . . 7
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .07870075 . . 7
    .03209662 . . 1
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .07870075 . . 7
    .03209662 . . 1
    .03209662 . . 1
    .15052333 . . 6
    .12454466 . . 4
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .15052333 . . 6
    .07870075 . . 7
    .07999493 . . 8
    .18556127 . . 5
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .07999493 . . 8
    .03209662 . . 1
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .07999493 . . 8
    .12454466 . . 4
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .07870075 . . 7
    .03209662 . . 1
    .07870075 . . 7
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .07999493 . . 8
    .18539837 . . 3
    .07999493 . . 8
    .07999493 . . 8
    .07999493 . . 8
    .15052333 . . 6
    .18539837 . . 3
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .07999493 . . 8
    .15052333 . . 6
    .15052333 . . 6
    .07999493 . . 8
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .15052333 . . 6
    .03209662 . . 1
    .07999493 . . 8
    .15052333 . . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    . .07599492 . 7
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .   .184801 . 6
    .   .184801 . 6
    .  .0296359 . 3
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    . .07599492 . 7
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .   .184801 . 6
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .   .184801 . 6
    .   .184801 . 6
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    .  .3693903 . 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .05084746 7
    . .  .59322035 8
    . .  .05084746 7
    . .  .05084746 7
    . .  .22881356 6
    . .  .22881356 6
    . . .016949153 3
    . .  .59322035 8
    . .  .22881356 6
    . .  .05084746 7
    . .  .22881356 6
    . .  .22881356 6
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .05084746 7
    . .  .22881356 6
    . .  .22881356 6
    . .  .22881356 6
    . .  .05084746 7
    . .  .59322035 8
    . .  .22881356 6
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .22881356 6
    . .  .22881356 6
    . .  .59322035 8
    . .  .22881356 6
    . .  .22881356 6
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .10169491 5
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .10169491 5
    . .  .59322035 8
    . .  .10169491 5
    . .  .10169491 5
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .10169491 5
    . .  .59322035 8
    . .  .10169491 5
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .22881356 6
    . .  .10169491 5
    . .  .10169491 5
    . .  .59322035 8
    . . .016949153 3
    . .  .59322035 8
    . .  .22881356 6
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    . .  .59322035 8
    
    
    end
    label values occupation_name za_all
    label def za_all 1 "senior management", modify
    label def za_all 3 "technicians", modify
    label def za_all 4 "technicians", modify
    label def za_all 5 "Q.P. commercial act. and services", modify
    label def za_all 6 "craftsmen, farmers, skilled w.", modify
    label def za_all 7 "machinery workers, veichle drivers", modify
    label def za_all 8 "unskilled professions", modify
    I was wondering how could I do a grap bar where the name of the occupation is displayed only once and not, as in my case, for every group in which I divided the population.
    Code:
    graph hbar percent1 percent2 percent3, over (occupation_name, sort(1)label(nolabel))graphregion(color(white)) ytitle (Percentage, size(small)) legend (label(1 "Native") label(2 "Other migrants") label(3 "Refugees")) bar(1, fcolor(yellow)) bar(2, fcolor(orange)) bar(3, fcolor(red)) blabel(group, position (outside) orientation(horizontal) size(vsmall))
    Thanks for you attention

  • #2
    Remove -blabel()- and add -asyvars-

    Code:
     
     graph hbar percent1 percent2 percent3, over (occupation_name, sort(1)label(nolabel))graphregion(color(white)) ytitle (Percentage, size(small)) legend (label(1 "Native") label(2 "Other migrants") label(3 "Refugees")) bar(1, fcolor(yellow)) bar(2, fcolor(orange)) bar(3, fcolor(red)) asyvars

    Comment


    • #3
      I don't understand these data, which look like proportions not percents to me. But in addition to Andrew Musau's suggestion, you may be better off with a different data structure.


      Code:
      gen which = . 
      forval j = 1/3 { 
          replace which = `j' if percent`j' < . 
      }
      
      gen percent = max(percent1, percent2, percent3)

      Comment


      • #4
        Thank you both. Andrew the graph looks good!
        Yes Nick you right are proportions, I will try your suggestion.

        Comment


        • #5
          Hi, I was wondering what are the command to create a table that gives me this statistics? I mean a table as the one in the picture that provides for each groups the proportion for each profession.

          Click image for larger version

Name:	Immagine 2022-02-05 230818.png
Views:	2
Size:	53.2 KB
ID:	1648629

          Thank you very much for your attention.

          Comment


          • #6
            Please start a new thread Enrico as your question is different from the original problem of this thread. You can post the data example in #1 in that thread.

            Comment

            Working...
            X