Announcement

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

  • Labels in graph bar

    I am working on the distribution of one variable by quintile.

    sysuse auto, clear
    xtile quin= weight, nq(5)
    pctile a= weight,nq(5)
    tab a
    graph bar price, over(quin)

    I do not know whether is possible to use quintile cutoffs values (as labels instead of 1,2,..,5

  • #2
    There is a -relabel()- option for -over()-
    Code:
    sysuse auto, clear
    xtile quin= weight, nq(5)
    sum weight, meanonly
    local max = r(max)
    _pctile weight, nq(5)
    return list
    graph bar price, over(quin, relabel(1 "`=r(r1)'" 2 "`=r(r2)'" /// 
        3 "`=r(r3)'" 4 "`=r(r4)'" 5 "`max'")   )

    Comment


    • #3
      Thanks Scott, this code was very usefull for me

      Comment


      • #4
        In a similar example, I only want to show the labels for some bars son I obtain this figure when I put this code:
        xtile ctile=gross_income,nq(50)
        _pctile gross_income, nq(50)
        graph bar p_costs p_ded p_ex, over(ctile, gap(0) label(labsize(tiny) angle(45) ) relabel(1 "`=r(r1)'" 10 "`=r(r10)'" 20 "`=r(r20)'" 30 "`=r(r30)'" 40 "`=r(r40)'" )) stack legend(order(1 "Costs" 2 "Exceptions" 3 "Deductions") pos(12) col(3))

        It is possible to exclude (or not show) the remaining labels and fix the decimal points to zero in the case on 10, 20, 30, and 40 labels?


        Click image for larger version

Name:	bar1.png
Views:	1
Size:	61.5 KB
ID:	1743525

        Comment


        • #5
          Yes, you have to create list of the bars with blank labels. For example:
          Code:
          sysuse auto, clear
          xtile quin= price, nq(50)
          sum price, meanonly
          local max = r(max)
          _pctile price, nq(50)
          
          //Bars without labels
          forv i = 1/50 {
              local mylist `mylist' `i' "  "
          }
          //Bars with labels
          foreach  j of numlist  1  10(10)40 {
              local mylist2 `mylist2' `j'  " `=r(r`j')' "
          }
          //Last bar label
          local mylist3 50 " `max' "
          
          local mylist `mylist' `mylist2' `mylist3'
          display "`"`mylist'"'"
          
          graph bar price, over(quin, relabel(`mylist' ) label(angle(45)) gap(*2) )

          Comment


          • #6
            Thats works very well with my data. Thank you so much

            Comment

            Working...
            X