Announcement

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

  • Bar Graph with Data table below graph

    Hi,

    Would anyone happen to know if Stata has the ability to create a bar graph with a data table right below the graph, similar to what Excel and SAS can do?


    http://www.exceldashboardtemplates.c...e-excel-graph/

    http://support.sas.com/techsup/notes/v8/35/774.html

  • #2
    There are several examples of graphs that attain that goal without adding a table underneath here: http://www.stata-journal.com/sjpdf.h...iclenum=gr0034
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      As usual, I like Maarten's answer. I'd add that you can get some of the way to where you want by using axis labels on two or more levels (see e.g. http://www.stata-journal.com/sjpdf.h...iclenum=gr0020)

      But both of the examples you cite strike me as unattractive design (all that scaffolding -- every number in its own box!), so I won't try to emulate them further. I am just picking up on the "I want to show numbers too" flavour.

      The SAS example is easier to build on. Here is the result of a little fooling around. The labmask command is explained in the paper cited by Maarten and must be downloaded first from the Stata Journal files.

      Code:
      clear
      input str7 year exp rev
      "1997/98" 302.3 310.8                                                                                                                    
      "1998/99" 323.0 328.7                                                                                                                    
      "1999/00" 354.4 363.5                                                                                                                    
      "2000/01" 381.7 390.2                                                                                                                    
      "2001/02" 426.8 429.1        
      end
      
      gen t = _n
      labmask t, values(year)
      
      gen t1 = t - 0.15
      gen t2 = t + 0.15
      
      twoway scatter exp t, ms(none) xla(1/5, valuelabel) yla(0(50)450, ang(h)) ///
      || bar exp t1, barw(0.3) ///
      || bar rev t2, barw(0.3) base(0)    ///
      || scatter exp t1, ms(none) mla(exp) mlabpos(12) ///
      || scatter rev t2, ms(none) mla(rev) mlabpos(12) ///
      legend(order(2 "Expenditure" 3 "Revenue")) ytitle("million USD")
      Click image for larger version

Name:	landry.png
Views:	1
Size:	22.0 KB
ID:	1384566


      Last edited by Nick Cox; 20 Apr 2017, 04:23.

      Comment

      Working...
      X