Hi All,
I have data that resembles the following:
------------------ copy up to and including the previous line ------------------
In the above, I have data on the variable value, for individuals by years. I wish to calculate the long differences for value by individual. This would be easy in a balanced panel, but int his case, each individual has potentially different number of observations. Basically, I wish to create a new variable, say value_long, which consists of subtracting the most recent year that value is available for each individual by the first year that value is available. So, for the first person, this variable would take on a value of 2-32, whereas for the second, it would take a value of 2-1. Notice that the most recent year is different for both. (Potentially the first year the individual has the observation could be different as well). Any help on this is much appreciated!
Best,
CS
I have data that resembles the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(year individual value) 1990 1 32 1991 1 3 1992 1 2 1993 1 1 1990 2 1 1991 2 3 1992 2 2 end
In the above, I have data on the variable value, for individuals by years. I wish to calculate the long differences for value by individual. This would be easy in a balanced panel, but int his case, each individual has potentially different number of observations. Basically, I wish to create a new variable, say value_long, which consists of subtracting the most recent year that value is available for each individual by the first year that value is available. So, for the first person, this variable would take on a value of 2-32, whereas for the second, it would take a value of 2-1. Notice that the most recent year is different for both. (Potentially the first year the individual has the observation could be different as well). Any help on this is much appreciated!
Best,
CS