Dear Stata Users,
Can you please help me with the following issue: I have a company (“gvkey”) with a person ID (pers_ID) who is associated with starting date (“start”) and final date (“final”) date at work. There are some missing values of “start” and “final”. What I need is to replace missing value of “start” with “final” if there is a non-missing “final” for a person who preceded a new person. The same is expected to be done for “final” – if there is a missing “final” it is supposed to be filled with “start” of a successor’s date. For instance, for firm = 006856 there is a missing “start” for “pers_ID”= 1386. However, there is a non-missing date for her predecessor (pers_ID = 1385). Thus “start” of “pers_ID”= 1386 is expected to be filled with “01nov1993”. Another example for firm = 010390 there is a missing “final” for “pers_ID”= 193, year=2009. However, there is a non-missing date for her successor (pers_ID = 14). Thus “final” of “pers_ID”= 193 is expected to be filled with “01jan2011”

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str24 gvkey double(fyear pers_ID) long(start final)
"001164" 1993  2627  9222     .
"001164" 1994  2627  9222     .
"001164" 1995  2627  9222     .
"001164" 1996  2627  9222     .
"001164" 1997  2627  9222     .
"001164" 1998  2627  9222     .
"001164" 1999  2627  9222     .
"001164" 2000  2627  9222     .
"001164" 2001  2627  9222     .
"001164" 2004 29310 15675     .
"004503" 1992   869     . 12171
"004503" 1993   870 12171 16801
"004503" 1994   870 12171 16801
"004503" 1995   870 12171 16801
"004503" 1996   870 12171 16801
"006856" 1992  1385 10897 12358
"006856" 1993  1385 10897 12358
"006856" 1994  1386     . 12751
"010374" 2007 19397 14245 18352
"010374" 2008 19397 14245 18352
"010374" 2009 19397 14245 18352
"010374" 2010 14379     . 18628
"010390" 2007   193 14245 18352
"010390" 2008   193 14245 18352
"010390" 2009   193 14245     .
"010390" 2010    14 18628     .
end
format %td start
format %td final