Announcement

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

  • Trend lines

    Hi Statlist,

    nice to meet you again.
    I would like to ask you a question about "shape and trend lines". I have in particular two bar plots. What I would like to do is to add a line to them which follow their shapes and then made the "average" trend line between the two. So the average line between the one of the first bar plot and the trend line of the second one.
    My data (example data) are as follows for the first bar plot:

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(Year ClassII)
    2004   68
    2005  140
    2006  243
    2007  189
    2008  176
    2009 1660
    2010  389
    2011 1279
    2012  499
    2013 1283
    2014 1344
    2015 1584
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 12 out of 12 observations


    And these for the second:


    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(Year ClassII)
    2004   68
    2005  140
    2006  243
    2007  189
    2008  176
    2009 1660
    2010  389
    2011 1279
    2012 1518
    2013  848
    2014  893
    2015 1584
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 12 out of 12 observations

    The code adopted for the bar plots is the following:

    Code:
    label var ClassII "Class 2"
    graph bar (asis) ClassII , over(Year) ylabel(0(100)2000, angle(0) grid)
    So I would like to add a line to both and then make the average line (average between the line of the first plot and the line of the second plot).


    Thank you very much,


    Federico

  • #2
    You really need to use twoway bar first to be able to add lines conveniently.

    Code:
    twoway bar ClassII Year || lfit ClassII Year
    gets you there directly -- and now your problem is statistical,. whether the model is a good idea for the data and the generating process.

    Comment


    • #3
      Thank you very much professor. I was thinking of simply do the line to the plot of the average bars (the average between the two dataset for each year) which I think is right.

      By the way, is there also a way to pick just the resulting "average line" between the two plots and put it to another bar plot ( a bar plot generated by a different dataset)?

      Comment


      • #4
        I think you're going to need to sort out your datasets first. You need three variables, not two; either

        Year ClassII_1 ClassII_2

        or

        Year ClassII Group

        Comment


        • #5
          Ok. I will try and let you know. Thank you very much for the moment!

          Comment

          Working...
          X