sort v3 ***control variable if only the WZ changed but not the job gen kontroll = 1 if v22 == 95 & v57 == 0 replace kontroll = 1 if v22 == 02 & v57 == 01 replace kontroll = 1 if v22 == 45 & v57 == 01 replace kontroll = 1 if v22 == 18 & v57 == 17 replace kontroll = 1 if v22 == 10 & v57 == 23 replace kontroll = 1 if v22 == 14 & v57 == 26 replace kontroll = 1 if v22 == 33 & v57 == 32 *** WZ93 classification = 35 becomes WZ03 = 34 , only two digit level replace kontroll = 1 if v22 == 35 & v57 == 34 replace kontroll = 1 if v22 == 50 & v57 == 34 *** WZ93 classification = 30 becomes WZ03 = 51, only two digit level replace kontroll = 1 if v22 == 85 & v57 == 55 replace kontroll = 1 if v22 == 60 & v57 == 63 *** WZ93 classification = 74 becomes WZ 03 = 72, only two digit level replace kontroll = 1 if v22 == 74 & v57 == 72 replace kontroll = 1 if v22 == 40 & v57 == 74 replace kontroll = 1 if v22 == 41 & v57 == 74 replace kontroll = 1 if v22 == 55 & v57 == 80 replace kontroll = 1 if v22 == 45 & v57 == 90 replace kontroll = 1 if v22 == 01 & v57 == 93 replace kontroll = 1 if v22 == 92 & v57 == 93 *** variable kontroll = 1 if there is a change but no job change replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] ***this is done until no more change happens replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] replace kontroll = 1 if kontroll[_n+1] == 1 & v3[_n+1] == v3[_n] & v22[_n+1] == v22[_n] *all WZ classification are take with 1 in the control variable *WZ03 gen WZ = v57 if kontroll == . *WZ93 replace WZ = v22 if WZ == . & kontroll == . ***WZ classification is filled with values that changes between WZ 93 and WZ 03 replace WZ = v57 if WZ == . & kontroll == 1 ***filling of the WZ variable taking the control variable into account replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] *until no more changes replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] replace WZ = WZ[_n+1] if WZ == . & kontroll == 1 & v3[_n] == v3[_n+1] drop kontroll