Hi,
I cant figure out on how to shift data to the left so that missings are removed. My problem is that the number places that have to be shiftet are individual per observation.
In my real data, I have 70 days where observations are missing at the beginning, and for each day I have 4 variables which need to be shiftet, but I hope the solution for the simple case can be generalized.
A simple example data is this:
In this example, for id 2, I need to shift data by one, while for id 3 it has to be shiftet by 3 and sid 4 by two, so that I end up with this:
I have tried to work with both loops and reshaping, but I cant get the individual number of shifts right.
Does anyone have a solution on this?
I am relatively new at STATA, so please bear over with me if this is a very easy problem :-)
Thanks!
-Anna
I cant figure out on how to shift data to the left so that missings are removed. My problem is that the number places that have to be shiftet are individual per observation.
In my real data, I have 70 days where observations are missing at the beginning, and for each day I have 4 variables which need to be shiftet, but I hope the solution for the simple case can be generalized.
A simple example data is this:
Code:
clear input id day1 day2 day3 day4 id day1 day2 day3 day4 1 5 4 . 2 2 . 1 2 5 3 . . . 4 4 . . 3 4 end
Code:
clear input id day1 day2 day3 day4 id day1 day2 day3 day4 1 5 4 . 2 2 1 2 5 . 3 4 . . . 4 3 4 . . end
Does anyone have a solution on this?
I am relatively new at STATA, so please bear over with me if this is a very easy problem :-)
Thanks!
-Anna

Comment