Dear all,

I turn to you for advice once again, as I am working for the first time on a dataset that is not in a time series (i.e. year and id are unique identifyers). My dataset looks a bit like the following :

id yearClosed tradeRecievables
113 2015 946440
113 2016 1037787
113 2014 6237883
113 2012 10739971
113 2013 8890283

Id = a corporation and there are thousands per sector, etc. What I am trying to do is generate a new variable that is the average of tradeRecievables[_n] - tradeRecievables[_n-1], per id. The different closing years are not equal accross the companies (some start at 2007 for example), so I need to tell Stata to treat the command by the set of yearClosed per id for all the ids available.

Is there a way to do that?

Thank you so much in advance!