Announcement

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

  • Trendline graph


    Hi!

    I am dealing with panel data and I would like to have a trend graph like the one posted below.

    It includes a dependent var and two independent vars (Yearly averages in log form).

    I shall be really grateful for you valuable guidance on this.


    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	280.5 KB
ID:	1559160

  • #2
    The Grunfeld dataset has panel identifier "company" and time variable "year". You want to first take the mean across years and then plot.

    Code:
    webuse grunfeld, clear
    preserve
    collapse invest mvalue kstock, by(year)
    line invest mvalue kstock year, scheme(s1color)
    restore
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	45.5 KB
ID:	1559177


    EDIT: As you state that your variables are in logs, you need to consider that averaging log values is not the same as taking averages and then logging. So, take this into account.
    Last edited by Andrew Musau; 16 Jun 2020, 16:00.

    Comment


    • #3
      The mean of the logarithms corresponds to the geometric mean. But the logarithm of the mean is different.

      Comment


      • #4
        Dear Andrew Musau,


        Many thanks for this. It really works. Can you tell me what to add if i want to keep let's say keep 10 years individually on x-axis like 2003, 2004, 2005 and so on till 2012.

        Comment


        • #5
          Dear Nick,

          Many thanks for this excellent point and further clarification. Much appreciated.

          Comment


          • #6
            Can you tell me what to add if i want to keep let's say keep 10 years individually on x-axis like 2003, 2004, 2005 and so on till 2012.
            In the graph in #2

            Code:
            line invest mvalue kstock year if inrange(year, 2003, 2012), scheme(s1color)

            Comment


            • #7
              Originally posted by Andrew Musau View Post

              In the graph in #2

              Code:
              line invest mvalue kstock year if inrange(year, 2003, 2012), scheme(s1color)
              I am sorry if you misunderstood. What I meant to say is that keeping each year on x-axis individually like 2003, 2004, 2005, 2006 ..... and so on.

              Comment


              • #8
                Are you asking about the xlabels?

                Code:
                line invest mvalue kstock year, xlab(2003/2012) scheme(s1color)

                Comment


                • #9
                  Originally posted by Andrew Musau View Post
                  Are you asking about the xlabels?

                  Code:
                  line invest mvalue kstock year, xlab(2003/2012) scheme(s1color)
                  Many thanks for this. Yes, I was talking about xlabels. Your support is much appreciated.

                  Comment


                  • #10
                    Originally posted by Nick Cox View Post
                    The mean of the logarithms corresponds to the geometric mean. But the logarithm of the mean is different.
                    Nick:

                    If your independent variable has some zeros then is it better to take natural log+1? because just taking a log of zero wouldn't make much sense.

                    Comment

                    Working...
                    X