Announcement

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

  • Displaying v values on xtline graph

    local y_title = "MIT Rate (%)"
    local x_title = "YearGroup"
    local title = "Top Marginal Income Tax Rate (MIT) by Region"
    local sub_title = "(Avg. MIT in % 2003-2010 & 2011-2018)"
    local footer = "Data Source: Individual income tax rates table - KPMG | GLOBAL - KPMG International"
    #delimit ;
    xtline mean_MIT_yearGroup_R, t(YearGroup) i(Region_Name) overlay
    graphregion(color(white)) ytitle(`y_title', height(5) size(vsmall)) ylabel(, labsize(small))
    xtitle(`x_title', size(vsmall)) xlabel(0 "Max MTR 2003-2010" 1 "Max MTR 2011-2018", labsize(tiny) angle(0.5))
    title(`title', size(small))
    subtitle(`sub_title', size (vsmall)) tline(0.5, lcolor(gs12) lpattern(dash))
    legend(col(3) row (3) label(1 "East Asia & Pacific") label(2 "Europe & Central Asia")
    label(3 "Latin America & The Caribbean")
    label(4 "Middle East & North Africa") label(5 "North America")
    label(6 "South Asia") label(7 "Sub-Saharan Africa")
    size(vsmall) symysize(vsmall) symxsize(vsmall) position(12) ring(0.5))
    text(-9 2015 "`footer'", size(tiny)) recast(connected) plot1opts(ms(Oh))
    plot2opts(ms(Th)) plot3opts(ms(T)) plot4opts(ms(+))
    plot5opts(ms(-)) plot6opts(ms(x)) plot7opts(ms(Dh)) msymbol(mean_MIT_yearGroup_R);
    #delimit cr

    Hi,

    I have the above code for the following graph. I want to display the values of "mean_MIT_yearGroup_R" on the graph. Can you help me how I can use mlabel() to display values in xtline grapgh? Thank you!
    Attached Files

  • #2
    graph dot with separate symbols for your time periods would work much better. Almost no one finds it easy to go back and forth between a legend and a graph.

    Show us the results of

    Code:
    tabdisp Region_Name YearGroup, c(mean_MIT_yearGroup_R)
    and people will be able to suggest better graphs.


    Comment


    • #3
      ok!

      Here they are:

      tabdisp Region_Name YearGroup, c(mean_MIT_yearGroup_R)

      -------------------------------------------------
      | YearGroup
      Reg | Max MTR 2003-2010
      ------------------------------+------------------
      East Asia & Pacific | 35.46429
      Europe and Central Asia | 34.62164
      Latin America & The Caribbean | 28.63108
      Middle East & North Africa | 14.54167
      North America | 32
      South Asia | 24.66667
      Sub-Saharan Africa | 28.94561
      -------------------------------------------------

      -------------------------------------------------
      | YearGroup
      Reg | Max MTR 2011-2018
      ------------------------------+------------------
      East Asia & Pacific | 30.87681
      Europe and Central Asia | 32.38474
      Latin America & The Caribbean | 28.83817
      Middle East & North Africa | 16.07692
      North America | 34.3125
      South Asia | 24.76132
      Sub-Saharan Africa | 30.99535
      -------------------------------------------------

      Comment


      • #4
        Here's one suggestion:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float mean_MIT_yearGroup_R str9 YearGroup str29 Region_Name
        35.46429 "2003-2010" "East Asia & Pacific"          
        30.87681 "2011-2018" "East Asia & Pacific"          
        34.62164 "2003-2010" "Europe and Central Asia"      
        32.38474 "2011-2018" "Europe and Central Asia"      
        28.63108 "2003-2010" "Latin America & The Caribbean"
        28.83817 "2011-2018" "Latin America & The Caribbean"
        14.54167 "2003-2010" "Middle East & North Africa"   
        16.07692 "2011-2018" "Middle East & North Africa"   
              32 "2003-2010" "North America"                
         34.3125 "2011-2018" "North America"                
        24.66667 "2003-2010" "South Asia"                   
        24.76132 "2011-2018" "South Asia"                   
        28.94561 "2003-2010" "Sub-Saharan Africa"           
        30.99535 "2011-2018" "Sub-Saharan Africa"           
        end
        
        encode YearGroup, gen(Period)
        
        egen Mean = mean(mean), by(Region)
        egen order = group(Mean)
        
        separate mean, gen(mean) veryshortlabel by(Period)
        
        set scheme s1color 
        graph dot (asis) mean?, over(Period, label(labsize(small)))  over(Region_Name, label(labsize(medsmall)) sort(order)) blabel(bar, format(%2.1f)) ///
        marker(1, ms(Oh)) marker(2, ms(+)) linetype(line) lines(lc(gs12) lw(vthin)) legend(off) /// 
        subtitle(Top MIT Rate (%)) exclude0 ysc(alt r(13 37.5))

        Click image for larger version

Name:	MIT.png
Views:	1
Size:	33.7 KB
ID:	1498191


        I suggest you avoid

        * alphabetical order for regions: meaningless outside dictionaries and gazetteers

        * a legend or vertical labels for regions: difficult or impossible to read.

        * abbreviations too

        You could use the space by putting region labels on two lines, But then "South" "Asia" would look worse just as "Latin America" "& The Caribbean" would look better.

        You could drop the numerical axis labels on the grounds that the numbers are shown.

        Comment


        • #5
          Thank you so much! I will try this

          Comment


          • #6
            My guess is that most people would want to write -- and to read -- an ordering by more recent values. That being so, here is a tweak -- and the code got simpler. (Often I have to write longer code before I can see how to shorten it.)

            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input float mean_MIT_yearGroup_R str9 YearGroup str29 Region_Name
            35.46429 "2003-2010" "East Asia & Pacific"          
            30.87681 "2011-2018" "East Asia & Pacific"          
            34.62164 "2003-2010" "Europe and Central Asia"      
            32.38474 "2011-2018" "Europe and Central Asia"      
            28.63108 "2003-2010" "Latin America & The Caribbean"
            28.83817 "2011-2018" "Latin America & The Caribbean"
            14.54167 "2003-2010" "Middle East & North Africa"  
            16.07692 "2011-2018" "Middle East & North Africa"  
                  32 "2003-2010" "North America"                
             34.3125 "2011-2018" "North America"                
            24.66667 "2003-2010" "South Asia"                  
            24.76132 "2011-2018" "South Asia"                  
            28.94561 "2003-2010" "Sub-Saharan Africa"          
            30.99535 "2011-2018" "Sub-Saharan Africa"          
            end
            
            encode YearGroup, gen(Period)
            separate mean, gen(mean) veryshortlabel by(Period)
            set scheme s1color
            
            graph dot (asis) mean?, over(Period, label(labsize(small)))  over(Region_Name, label(labsize(medsmall)) sort(mean2)) blabel(bar, format(%2.1f)) ///
            marker(1, ms(Oh)) marker(2, ms(+)) linetype(line) lines(lc(gs12) lw(vthin)) legend(off) ///
            subtitle(Top MIT Rate (%)) exclude0 ysc(alt r(13 37.5))
            Click image for larger version

Name:	MIT2.png
Views:	1
Size:	27.3 KB
ID:	1498250



            I am leaving the y axis labels in. I can imagine talking through this in a paper or presentation as

            Top rates have varied regionally between about 15 and about 35%, In particular ....

            Logically there is no more information in the axis labels than in the individual values shown as text. But psychologically a little bit of repetition can be helpful.

            When a graph has something of a table flavour, the horizontal axis labels (here so far as graph dot is concerned the y axis) often go better at the top.

            I am naturally mindful of the convention that time "belongs" on the horizontal axis. Know that I played with several variants of that idea without finding a graph I preferred to this.

            It doesn't seem to be documented that blabel(bar, ) is allowed with graph dot. It was a happy guess that the code would allow it.

            This kind of comparison -- a measured value of interest, varying within a categorical framework on two or more levels -- seems very common across several sciences.

            Comment


            • #7
              ok great, I made it! Thank you for all your input. It is very helpful in my analysis and research.
              Last edited by Sana Elahi; 14 May 2019, 11:40.

              Comment

              Working...
              X