Announcement

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

  • Calculating difference between observations

    Hi everybody,

    I want to calculate the difference between MF y and MF y-1, I want to calculate it with the (new-old/old) formula. However when i type the following command:

    gen changeMF = (MF - MF[n-1]) / MF[n-1]
    it calculates something, but it is not the percentual change in MF.
    I want to calculate it per firm, that does not work either.
    Can someone help me?

    Thanks in advance

  • #2
    If you really typed

    Code:
    gen changeMF = (MF - MF[n-1]) / MF[n-1]
    then presumably there is one and only one variable or scalar whose name begins with n and it was used for calculation. To understand how that works, consider these results:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . gen weight2 = weight[mpg]
    
    . l weight* in 1/2
    
         +------------------+
         | weight   weight2 |
         |------------------|
      1. |  2,930      3600 |
      2. |  3,350      3220 |
         +------------------+
    
    . di weight[22]
    3600
    
    . di weight[17]
    3220
    You may have meant

    Code:
    gen changeMF = (MF - MF[_n-1]) / MF[_n-1]
    although something like

    Code:
    tsset firm year
    gen change MF = (MF - L.MF) / (L.MF)
    is much, much better, not least to avoid nonsensical calculations relating the first value for one form to the last value of the previous firm.
    Last edited by Nick Cox; 07 Jun 2015, 02:48.

    Comment


    • #3
      I don't know what your application is, but in economic applications it usually makes more sense to take logs and interpret their difference as a percentage change than to calculate a literal percentage change. So:

      Code:
      tsset firm year
      gen lnMF = ln(MF)
      gen changeMF = D.lnMF

      Comment

      Working...
      X