Announcement

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

  • Generate a variable: average annual growth rate

    Dear Statalisters,
    I'd like to generate a variable "γ" called the average annual growth rate according to the formula :
    Click image for larger version

Name:	2023-08-16 15.53.52.png
Views:	1
Size:	4.9 KB
ID:	1723980

    Where x is the revenue in year t, n is the number of years, γ is the average annual growth rate.
    I hope to have the commands to generate γ.
    Thank you in advance!

    Best,
    Josh

    I attached an example of the sample.
    -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(id year revenue)
    1 2001 100
    1 2002  20
    1 2003 100
    1 2004 110
    1 2005 125
    2 2003  60
    2 2004  50
    2 2005  90
    3 2001 190
    3 2002 180
    3 2003 100
    3 2004  90
    end
    ------------------

  • #2
    You'll get more interesting responses I think, but this works:

    Code:
    xtset id year
    bys id (year): g idN = _n
    egen base = mean(cond(idN==1, revenue, .)), by(id)
    g y = (revenue/base)^(1/(idN-1)) - 1

    Comment


    • #3
      Originally posted by George Ford View Post
      You'll get more interesting responses I think, but this works:

      Code:
      xtset id year
      bys id (year): g idN = _n
      egen base = mean(cond(idN==1, revenue, .)), by(id)
      g y = (revenue/base)^(1/(idN-1)) - 1
      Thank you George for your suggestion. But I found the variable I get is time-variant, I think what I need should be a time-invariant variable.

      Best,
      Josh

      Comment


      • #4
        To give you a sense of what's going on, observe the data for this:

        Code:
        bys id:  g base = revenue[1]
        bys id:  g last = revenue[_N]
        bys id: g N = _N
        So, the growth rate from firsr/last period is


        Code:
         
         bys id: g growth = (revenue[_N]/revenue[1])^(1/_N)-1
        But note that the number of years used to compute that will be different if the panel is not balanced.

        Comment


        • #5
          Originally posted by George Ford View Post
          To give you a sense of what's going on, observe the data for this:

          Code:
          bys id: g base = revenue[1]
          bys id: g last = revenue[_N]
          bys id: g N = _N
          So, the growth rate from firsr/last period is


          Code:
          bys id: g growth = (revenue[_N]/revenue[1])^(1/_N)-1
          But note that the number of years used to compute that will be different if the panel is not balanced.

          Yes I use unbalanced panel data.
          Thank you!

          Comment

          Working...
          X