I am using panel data in which a series of entities have varying values for the variable "q". I would like to compute a new variable "slope" equal to the running value of the slope of the values of "q" across n prior observations.
The data look like this:
entity #, observation # for entity, q
1,1,-1
1,2,1
1,3,-3
1,4,3
1,5,2
1,6,-2
...many more observations for entity 1...
2,1,3
2,2,-2
2,3,4
2,4,0
2,5,-2
2,6,1
etc.
So, for example, beginning in observation #4 for entity #1, I might have "slope" equal to the slope of the values for "q" across the three prior observations for that entity, values -1, 1 and -3 in, respectively, observations 1 through 3.
Can you recommend code to accomplish this?
Thank you!
The data look like this:
entity #, observation # for entity, q
1,1,-1
1,2,1
1,3,-3
1,4,3
1,5,2
1,6,-2
...many more observations for entity 1...
2,1,3
2,2,-2
2,3,4
2,4,0
2,5,-2
2,6,1
etc.
So, for example, beginning in observation #4 for entity #1, I might have "slope" equal to the slope of the values for "q" across the three prior observations for that entity, values -1, 1 and -3 in, respectively, observations 1 through 3.
Can you recommend code to accomplish this?
Thank you!
Comment