Announcement

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

  • sparklines (or similar) with varying y-axis values by case

    Hello. I wish to graph the within-state (US states) variation of a performance measure over time for 45 states. However, some states have a much lower average performance than others, and some states have greater variability in the performance measure (the y variable).
    Since my goal is to show these cycles within states, I'd like to have a way to have the y-variable scaled by state. If I only graph a few states, having just one scale wouldn't be a problem. However, with all 45 states, a single scale makes some lines appear flat.

    Is there a way to create a compact graph--like sparklines--with a y-scale set for each state? Otherwise, I may need to create three sets of graphs of groups of states with the groups based on the maximum performance measure. I hope this question is clear.

    In the -dataex- sample below, I just include a few states that show such variability in the maximum performance value. "Ratio" is the performance variable; it is measured every two years.

    Thank you.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str2 stateabbr float(year ratio)
    "AR" 2006 .031210987
    "AR" 2008          .
    "AR" 2010   .0212996
    "AR" 2012  .04330367
    "AR" 2014  .11587688
    "AR" 2016  .18206713
    "AR" 2018  .13653782
    "AR" 2020  .11991835
    "MO" 2006  .05226283
    "MO" 2008   .1468446
    "MO" 2010   .3028242
    "MO" 2012   .2421415
    "MO" 2014  .18079086
    "MO" 2016   .1796066
    "MO" 2018   .1114988
    "MO" 2020  .09073064
    "MT" 2006   .1025776
    "MT" 2008  .12931456
    "MT" 2010   .1310258
    "MT" 2012  .09517085
    "MT" 2014  .13652705
    "MT" 2016  .23533443
    "MT" 2018 .034735452
    "MT" 2020  .05583256
    "OH" 2006   .0916762
    "OH" 2008   .2261373
    "OH" 2010   .3317917
    "OH" 2012   .4606627
    "OH" 2014   .2346816
    "OH" 2016   .4142646
    "OH" 2018  .33637035
    "OH" 2020   .3177344
    "OK" 2006  .07273434
    "OK" 2008 .073036894
    "OK" 2010  .04667522
    "OK" 2012   .0409433
    "OK" 2014 .022541795
    "OK" 2016  .15999486
    "OK" 2018  .12739336
    "OK" 2020  .06465035
    end

  • #2
    Here is an example. The critical option is the yrescale suboption within the by() option.

    Code:
    webuse grunfeld
    twoway line invest year, by(company, compact note("") yrescale) sort
    Alternatively, you could use a log-scale to see changes that happen at different orders of magnitude. This could allow you to use the same axes for all States and still see what is happening in each state.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten Buis made a great suggestion to try first. Another of several other possibilities is to rank the states somehow and divide into say 4 groups of 11 or 12, highest to lowest. Use direct labelling not legends so that AL AK … WY appears as text at the end of each series.

      Ratios often benefit from log scale too.

      myaxis from the Stata Journal can help with the ranking.
      Last edited by Nick Cox; 22 Jul 2022, 01:54.

      Comment


      • #4
        The suggestion in #3 may be what you had in mind in #1. There is no advantage of 3 panels (graph sense) over 4 unless you are putting them on the same row.

        Comment


        • #5
          Thank you both!

          Comment

          Working...
          X