I have a question regarding inserting observations in my dataset. My dataset currently looks like:
Year X Y Z
2013 1 2 z(1,2)13
2014 1 2 z(1,2)14
2013 1 3 z(1,3)13
2014 1 3 z(1,3)14
2014 1 4 z(1,4)14
2013 1 5 z(1,5)12
2014 1 5 z(1,5)14
Here, think of X and Y as different individuals. The way to read this is that individuals X and Y are linked through a common value that they share Z(x,y) in year (13) or (14). Hence, Z(1,2)13 reads the value of variable Z for individuals 1 and 2 in the year 13. I want to create a new variable Z' such that it is the first difference of the variable Z by individual pairing over the 2 years. However, my problem is as follows. As can be seen in the example dataset, individuals 1,4 only have observations for one time period.
I want to ideally create a row of zeros whenever this happens.
A complications is that when I take the difference, I want it to take the (value -0) if the missing year is 2013 but (0-value) if the missing year is 2014. I do not know how to implement this in the dataset. I have tried numerous things in vain.
I guess if I were able to declare my data as panel, first difference operations may be easier to recognize. However, given that my data is not really longitudinal in the conventional sense, Stata responds with an error message:
repeated time values within panel
r(451);
Any help is greatly appreciated.
Thanks!
Year X Y Z
2013 1 2 z(1,2)13
2014 1 2 z(1,2)14
2013 1 3 z(1,3)13
2014 1 3 z(1,3)14
2014 1 4 z(1,4)14
2013 1 5 z(1,5)12
2014 1 5 z(1,5)14
Here, think of X and Y as different individuals. The way to read this is that individuals X and Y are linked through a common value that they share Z(x,y) in year (13) or (14). Hence, Z(1,2)13 reads the value of variable Z for individuals 1 and 2 in the year 13. I want to create a new variable Z' such that it is the first difference of the variable Z by individual pairing over the 2 years. However, my problem is as follows. As can be seen in the example dataset, individuals 1,4 only have observations for one time period.
I want to ideally create a row of zeros whenever this happens.
A complications is that when I take the difference, I want it to take the (value -0) if the missing year is 2013 but (0-value) if the missing year is 2014. I do not know how to implement this in the dataset. I have tried numerous things in vain.
I guess if I were able to declare my data as panel, first difference operations may be easier to recognize. However, given that my data is not really longitudinal in the conventional sense, Stata responds with an error message:
repeated time values within panel
r(451);
Any help is greatly appreciated.
Thanks!
Comment