Hi, I would like to create a variable that would track a tenure of executives (number of years with the company), the problem is that sometimes executives rejoin the company so it is not as easy as just calculating the difference between date joined and date left. The dates are recorded in 4 separate variables joined company (joined_co), rejoined company (rejoin), left company (leftco) and left company after rejoining (releft). Here is also example of the dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(leftco releft joined_co rejoin) double year str6 gvkey long execid
    .     .     .     . 2000 "015208"  9684
15341     .     .     . 2000 "006169" 24339
    .     . 12570     . 2000 "030059" 25599
17166     . 14092     . 2000 "010411" 19399
    .     . 13163     . 2000 "002938" 13437
    .     . 13939     . 2000 "005330" 19275
    .     . 14884     . 2000 "001998" 23010
    .     .     .     . 2000 "065351" 14666
16842     . 13149     . 2000 "027794" 18582
    .     .     .     . 2000 "013397"  6170
15430     . 14641     . 2000 "008745" 22396
    .     .     .     . 2000 "122077" 20312
16933     . 13970     . 2000 "014895" 25419
    .     . 13118     . 2000 "030059" 18060
15371     .  3439     . 2000 "007922" 12751
    .     .     .     . 2000 "013041" 23053
    .     .     .     . 2000 "062814" 21483
    .     .     .     . 2000 "009772" 24534
    .     .     .     . 2000 "030870" 22742
    .     .     .     . 2000 "025434" 22926
15218     .     .     . 2000 "006379" 15002
16892     . 14457     . 2000 "001111" 22982
    .     . 10166     . 2000 "030870" 17713
    .     . 14291     . 2000 "005301" 21791
    .     .     .     . 2000 "005961" 19446
15043     .     .     . 2000 "024315" 22252
15043     . 13939     . 2000 "028700" 21889
16405     . 14457     . 2000 "008446" 19233
    .     .     .     . 2000 "063621" 21806
    .     . 14823     . 2000 "028700" 24019
13230     .     . 14223 2000 "012631"  2372
    .     . 14884     . 2000 "144396" 25537
    .     . 14647     . 2000 "007401" 23620
    .     .     .     . 2000 "006116" 18211
17333     .     .     . 2000 "007692" 21373
    .     . 13911     . 2000 "008214" 18690
    .     .  9497     . 2000 "022612" 18020
15340     . 14854     . 2000 "029345" 23311
17166     .  3653     . 2000 "001920" 14572
    .     . 11323     . 2000 "122778" 22720
14867 16883 13975 15048 2000 "011669" 17924
    .     .     .     . 2000 "001837" 17966
    .     .     .     . 2000 "009155" 10314
    .     .     .     . 2000 "011300" 12659
15312     .     .     . 2000 "060797" 19713
15303     .     .     . 2000 "009217" 18882
    .     .     .     . 2000 "008007" 14368
    .     .     .     . 2000 "008402" 22473
    .     .     .     . 2000 "014820" 22768
    .     .     .     . 2000 "024531" 22139
16832     . 12600     . 2000 "011669" 15428
    .     .     .     . 2000 "005791" 18012
    .     .     .     . 2000 "007824" 19382
    .     . 13880     . 2000 "026021" 19795
    .     .     .     . 2000 "004737" 24432
16861     .     .     . 2000 "009299" 23251
    .     . 14488     . 2000 "001686" 21665
14844     .     .     . 2000 "024704" 21759
    .     .     .     . 2000 "112178" 18740
    .     .     .     . 2000 "063690" 13526
    .     .     .     . 2000 "024608" 20681
17044     .     .     . 2000 "003126" 17690
    .     . 11139     . 2000 "061153" 23655
15350     . 14619     . 2000 "024621" 19479
14641     .  6940     . 2000 "014412"  4510
    .     .     .     . 2000 "009563" 18672
    .     .     .     . 2000 "007409" 24506
15743     .     .     . 2000 "010420" 20896
17410     .     .     . 2000 "009466" 11878
    .     .  1096     . 2000 "005216"   481
    .     .     .     . 2000 "007536" 16410
    .     .     .     . 2000 "011313" 19528
    .     .     .     . 2000 "007180" 20861
    .     .     .     . 2000 "004990" 12730
    .     .     .     . 2000 "001773" 14957
    .     . 12904     . 2000 "014897" 11431
    .     .  7305     . 2000 "028758" 20161
    .     .     .     . 2000 "003373" 19078
    .     .     .     . 2000 "026012" 17800
    .     .     .     . 2000 "011925"  9002
    .     . 13605     . 2000 "028018" 25212
    .     .  9132     . 2000 "010121" 15659
    .     . 13779     . 2000 "010190" 10913
    .     .     .     . 2000 "006475" 10489
    .     .     .     . 2000 "011584" 25353
    .     .     .     . 2000 "013365" 15879
    .     .     .     . 2000 "119417" 21140
    .     .  8766     . 2000 "001678" 21162
    .     .     .     . 2000 "001243" 25370
16919     . 13737     . 2000 "006733" 15017
    .     .  7579     . 2000 "024291"  6883
    .     .     .     . 2000 "118121" 22201
    .     .     .     . 2000 "003221" 24737
    .     .     .     . 2000 "007127" 21451
    .     .     .     . 2000 "024856" 21349
    .     .     .     . 2000 "002518" 25023
    .     .     .     . 2000 "002002" 24475
    .     .     .     . 2000 "010507" 24708
    .     .     .     . 2000 "029392" 24571
    .     . 12297     . 2000 "065215" 20114
end
format %d leftco
format %d releft
format %d joined_co
format %d rejoin
Thanks in advance for any help.