Reputation: 125
I have a dataset in Stata of the following form:
Individual Year VariableX VariableY
1 2013 x11 y11
2 2013 x12 y12
. . . .
N 2013 x1N y1N
1 2014 x21 y21
2 2014 x22 y22
. . . .
N 2014 x2N y2N
As can be seen above, the dataset is sorted by year. I now wish to create another variable Z
, the change in X
by Year
, that is, for individual 1 for instance, her value for this variable should be x21
- x11
(her value of x
in year 2014 - her value of x
in year 2014).
Upvotes: 0
Views: 429
Reputation: 1431
When working with panel data, you can tell Stata how your data is arranged with:
xtset individual year
One way of accessing the the one year lagged value is by using the L.
operator:
generate z = x - L.x
Other than that you should probably read up on manipulating panel data in Stata.
Upvotes: 1