Announcement

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

  • Add a line to a stack graph

    Hello Stata Community,

    I am currently working on the graph with the distribution of taxes. Now I want to add a line with the total value of the variables used in the stack graph but I don't know how to do it. Here is my code:

    // f) Stacked graph for Spain & US

    //new variable with country specifications:

    gen countryspec = 1 if country == "Spain"
    replace countryspec = 2 if country == "United States"


    label define countryspecname 1 "Spain" ///
    2 "United States"

    label values countryspec countryspecname


    // Graph:

    graph bar (sum) value if value > 0.05, ///
    over(tax, label(labsize(vsmall))) ///
    over(year) by(countryspec) asyvars stack ///
    line sum year ///
    bargap(10) ///
    line value ///
    ytitle("Tax revenue as % of GDP", size(small)) ///
    note("Data source: OECD, 2022") ///
    xsize(10) ///
    ysize(6) ///
    title("Tax structure of US and Spain", span size(small)) ///
    blabel(bar, orientation(horizontal) position(center) size(vsmall) color(white) format(%4.1f))

    In the End it should look like this:

    Click image for larger version

Name:	981E530D-4778-4264-833A-FD29AF30A306_4_5005_c.jpeg
Views:	1
Size:	38.3 KB
ID:	1685207


    Thanks in advance
Working...
X