Announcement

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

  • Calculating growth rate first and last observation

    Dear Statalist,

    I want to calculate the total growth rate of a variable over the entire period (2010-2016) however my data set is unbalanced and therefore starting years and/or ending years are different. I was wondering how to calculate the total growth rate by calculating; (last occurrence - first occurrence) / (first occurrence) as i am interested in the growth of this variable over the entire data set.

    Thank you for taking the time reading this!

    Kind Regards,

    Max Verheijen





  • #2

    Let's assume that there are no missing values. Then


    Code:
    bysort id (year) : gen wanted = (whatever[_N] - whatever[1]) / whatever[1]
    With missing values present there are other approaches. Here's one:

    Code:
    gen OK = !missing(whatever) 
    bysort OK id (year) : gen wanted = (whatever[_N] - whatever[1]) / whatever[1] 
    bysort id (wanted) : replace wanted = wanted[1]
    You should surely want to keep track too of the number of years concerned

    Code:
    gen OK = !missing(whatever) 
    bysort OK id (year) : gen wanted = (whatever[_N] - whatever[1]) / whatever[1] 
    by OK id: gen diff = year[_N] - year[1] if OK 
    bysort id (wanted) : replace wanted = wanted[1] 
    by id: replace diff = diff[1]
    The code here is not tested. You didn't give a data example to work on.

    Comment

    Working...
    X