Hi Statalist users,

I want to know how I would generate a variable whose values are the slope or growth of the value of another variable across time. For instance, if I were to use the following example set:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(id trt y1 y2 y3 y4)
1 1 3.5 4.5 7.5 7.5
2 1 6.5 5.5 8.5 8.5
3 1 3.5 4.5 7.5 9.5
4 1 3.5 3.5 6.5 8.5
5 2   1   2   5  10
6 2   2   3   6  10
7 2   2   4   5   9
8 2   2   3   6  11
end
How would I generate another variable, call it "slope," that would be the value of the slope of each case across y1 through y4 on some continuous variable represented by the values under y1-y4? It would be different than merely taking the difference between y4 and y1 because I want to take the in-between year changes into account. Would I have to make the data long first in order to do this? I.e., with the above data loaded,

Code:
reshape long y, i(id) j(time)
The whole point of this is to take into account the growth or change of each case across time in a matching equation (i.e., a logit model) that I will use to find matches between the treated and untreated, represented in the above dataset by the values 1 and 2 under the trt variable. For example, two cases whose values had similar growth patterns--increased from y1 to y2 by a similar amount, then decreased from y2 to y3 by a similar amount, then increased from y3 to y4 by a similar amount--but whose baseline y1 values might not be the same would have closer p-scores in a propensity matching analysis than two cases whose values for y4 are very close but whose growth patterns differed a lot. I have next to no experience with longitudinal or time series models, and so I may be completely looking at this the wrong way.

Thanks!