Dear Statalist,
I have an unbalanced panel dataset with missing data between the first and last observation month in some of the panel ids. Example data:
I can fill the gaps using this code:
which results in the following output:
However, for each ID, I would like to have two additional observations: One in the month prior to the first observation, the other in the subsequent month of the last, so that the output ends up looking like this:
Kind regards
Ingo
I have an unbalanced panel dataset with missing data between the first and last observation month in some of the panel ids. Example data:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float time str1 id float obsvar 744 "A" 20 745 "A" 20.5 747 "A" 19.5 749 "A" 18 693 "B" 100 697 "B" 120 end format %tm time
Code:
encode id, gen(id_dum) xtset id_dum time tsfill
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float time str1 id float obsvar long id_dum 744 "A" 20 1 745 "A" 20.5 1 746 "" . 1 747 "A" 19.5 1 748 "" . 1 749 "A" 18 1 693 "B" 100 2 694 "" . 2 695 "" . 2 696 "" . 2 697 "B" 120 2 end format %tm time label values id_dum id_dum label def id_dum 1 "A", modify label def id_dum 2 "B", modify
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float time str1 id float obsvar long id_dum 743 "A" . 1 744 "A" 20 1 745 "A" 20.5 1 746 "" . 1 747 "A" 19.5 1 748 "" . 1 749 "A" 18 1 750 "A" . 1 692 "B" . 2 693 "B" 100 2 694 "" . 2 695 "" . 2 696 "" . 2 697 "B" 120 2 698 "B" . 2 end format %tm time label values id_dum id_dum label def id_dum 1 "A", modify label def id_dum 2 "B", modify
Ingo
Comment