Announcement

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

  • Align scale of two y-axis

    I am trying hard to alignt the scale of the two Y-Axis but Stata seems to override my instructions. Any hints how I can get the 0 to be one the same vertical height?

    Illustrative code, let me know if you want a fake MWE.

    Code:
    qui sum year
    local beg = r(min)
    local end = r(max)
    
    # delimit ;
        twoway  (line realGDPpcgrowth year, yaxis(2) yscale(r(-6 6)) ylabel(-6(2)6) ytitle("GDP growth %", axis(2) size(small))) ||
                (line wageGrowth year, yaxis(1) yscale(r(-6 6)) ylabel(-6(2)6) ytitle("Wage growth %", axis(1) size(small))),
                title("") xtitle("") xsc(r(`beg' `end')) xlabel(`beg'(2)`end')
                legend(order(1 "Real GDP per capita growth" 2  "Real wage growth") rows(1));
    # delimit cr


    Click image for larger version

Name:	figure1e1.PNG
Views:	1
Size:	67.8 KB
ID:	1734522

  • #2
    The problem seems to be one in which plotting two variables on exactly the same scale is not just possible but the best approach to allow comparison and interpretation. The existing graph is hard work and not likely to be improved by tweaking.

    Either way, showing us the data using dataex would ease discussion and allow experiment.

    Comment


    • #3
      You might be right, I just wish Stata wouldnt make that decision for me..

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int year float(realGDPpcgrowth wageGrowth)
      2000    .  .57589775
      2001  2.9   .7297742
      2002  1.7   .5875737
      2003  -.1   .3324065
      2004  -.6 -.01293407
      2005  1.3   .3617509
      2006   .8 -.02049213
      2007  3.9        -.3
      2008    3         .4
      2009   .9          0
      2010 -5.7         .9
      2011  4.1          2
      2012  3.8        1.3
      2013   .3         .9
      2014   .3        1.7
      2015    2        2.3
      2016  1.2        1.5
      2017  1.9        1.1
      2018  2.3        1.4
      2019   .7        1.6
      2020   .8        -.7
      2021 -3.9 -.02924583
      2022  2.5  -2.240647
      end

      Comment


      • #4
        Wrong way round, or so I suggest. If Stata superimposes series and uses the same coordinate system, it's because (it sincerely thinks) you're asking it to do that. You can get something different by asking for it. That is

        Code:
        line y1 y2 x
        does not mean to Stata choose scales for y1 and y2 that are different and plot against x. That's programmable with some criterion or rules for how scales should be chosen but not, I suggest, otherwise.

        With your data example (thanks!) the two series are a tangle, but it's in the economics what the story is. If you want to separate the two series, then there are many solutions, but completely separate traces can work as well as most. See e.g. multiline from SSC. https://www.statalist.org/forums/for...ailable-on-ssc

        In the next version I would remove the useless xtitle "year", surely not needed by anyone expected to think about your graphics.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input int year float(realGDPpcgrowth wageGrowth)
        2000    .  .57589775
        2001  2.9   .7297742
        2002  1.7   .5875737
        2003  -.1   .3324065
        2004  -.6 -.01293407
        2005  1.3   .3617509
        2006   .8 -.02049213
        2007  3.9        -.3
        2008    3         .4
        2009   .9          0
        2010 -5.7         .9
        2011  4.1          2
        2012  3.8        1.3
        2013   .3         .9
        2014   .3        1.7
        2015    2        2.3
        2016  1.2        1.5
        2017  1.9        1.1
        2018  2.3        1.4
        2019   .7        1.6
        2020   .8        -.7
        2021 -3.9 -.02924583
        2022  2.5  -2.240647
        end
        
        label var realGDPpcgrowth "real GDP pc"
        label var wageGrowth "wages"
        local explain "subtitle(yearly % growth, place(w))"
        
        line *rowth year, yli(0) name(line1, replace) `explain'
        
        multiline *rowth year, yli(0) name(line2, replace) by(`explain')
        Click image for larger version

Name:	line1.png
Views:	1
Size:	67.9 KB
ID:	1735073
        Click image for larger version

Name:	line2.png
Views:	1
Size:	56.5 KB
ID:	1735074

        Comment


        • #5
          Note that multiline by default ignores 2000 for which one variable has a missing value, but the option missing can override that. Similarly different colours are available after its separate option.

          Comment

          Working...
          X