Announcement

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

  • Year over Year Calculations

    Hello everyone,
    I am analyzing a sample of many firms with data recorded over a period of 30 years. I have data related to Total Assets (End of Period), but in order to go on with my analysis I need (for every firm in every year) the Average Total Assets between current year and previous year.
    For example, let's say I have three firms (X, Y and Z) with data related to total assets for three years (20X1, 20X2, 20X3). I'm looking for a single function that compute the average total assets between 20X1 and 20X2 for firm X, the average total assets between the same years for firm Y, the average total assets between 20X2 and 20X3 for firm X, and so on.
    Thanks for the attention.

    Daniel
    Last edited by Danilo Sultanazzi; 06 Jul 2019, 18:07.

  • #2
    No data example here: please read and act on FAQ Advice #12. You seek a command, as in general terms functions don't exist to do this. In Stata functions and commands are quite different.

    This should show some technique:

    Code:
    webuse grunfeld
    ssc install rangestat
    help rangestat
    rangestat (mean) kstock, int(year -1 0) by(company)
    The calculation is also easy like this:

    Code:
    xtset company year
    gen double mean_kstock = (kstock + L1.kstock)/2
    The results are identical, except that rangestat averages what it sees, and returns a single non-missing value as its own mean, whereas the time series operator returns missing for the value before the first observation in a panel.

    Code:
    . l company *kstock* in 1/20
    
         +------------------------------------------+
         | company   kstock   kstock_~n   mean_ks~k |
         |------------------------------------------|
      1. |       1      2.8         2.8           . |
      2. |       1     52.6   27.699999   27.699999 |
      3. |       1    156.9      104.75      104.75 |
      4. |       1    209.2      183.05      183.05 |
      5. |       1    203.4       206.3       206.3 |
         |------------------------------------------|
      6. |       1    207.2       205.3       205.3 |
      7. |       1    255.2       231.2       231.2 |
      8. |       1    303.7      279.45      279.45 |
      9. |       1    264.1   283.90001   283.90001 |
     10. |       1    201.6   232.85001   232.85001 |
         |------------------------------------------|
     11. |       1      265       233.3       233.3 |
     12. |       1    402.2   333.60001   333.60001 |
     13. |       1    761.5   581.85001   581.85001 |
     14. |       1    922.4   841.95001   841.95001 |
     15. |       1   1020.1      971.25      971.25 |
         |------------------------------------------|
     16. |       1     1099     1059.55     1059.55 |
     17. |       1   1207.7     1153.35     1153.35 |
     18. |       1   1430.5      1319.1      1319.1 |
     19. |       1   1777.3      1603.9      1603.9 |
     20. |       1   2226.3      2001.8      2001.8 |
         +------------------------------------------+
    .
    Last edited by Nick Cox; 07 Jul 2019, 04:19.

    Comment

    Working...
    X