I have a dataset which records the change of a variable X over time for different people. The dataset is organized as follows: a new observation is created when the variable X changes and a corresponding Start and End dates are reported for the period this value refers to. Anyway, the value of X can only change in the first day of each month and refers to the entire month. If the value of X is zero for a certain period it is not recorded. You can reproduce an example of the data for the year 2020 with the code reported below.
I would need to reshape the data in a panel data format with monthly observations, even for the periods not reported with X=0. In the example, I want to have 24 observations (12 months for each ID). Any idea on how to proceed?
Thanks!
ID | Start | End | X |
1 | 01jan2020 | 30apr2020 | 5 |
1 | 01may2020 | 31aug2020 | 10 |
1 | 01sep2020 | 30nov2020 | 15 |
2 | 01jan2020 | 01may2020 | 7 |
2 | 01jul2020 | 31dec2020 | 14 |
input float(ID Start End X)
1 21915 22035 5
1 22036 22158 10
1 22159 22249 15
2 21915 22066 7
2 22097 22280 14
end
format %td Start
format %td End
[CODE]
0 Response to Reshape data from time intervals to panel data
Post a Comment