I am working with 18 waves of panel data (HILDA) and in each wave, respondents state their marital status (details below). I want to estimate the length of relationships for those in my data. I am not sure how to do this, but understand I should use time dummies.

I have had help with code which uses dummies to identify a change in relationship status, such as from single to married. I have similar code for other relationship changes (i.e. single to de facto, de facto to married, de facto to separated, married to separated, separated to divorced, etc). However, I feel this code is clumsy, long winded and feel there is more direct way to code it.

I would appreciate help to track a relationship from start to finish to be able to measure the length of relationships (in years).

Code:
sort id wave
cap drop droppout 
gen droppout = mi(marstat) // marital status
cap drop if_* 

gen if_sin_to_mar = 0 if droppout == 0
bys id (wave): replace if_sin_to_mar = 1 if marstat==1 & 1.marstat== 6 & 1.mrcurr != . & mrcurr != .
bys id (wave): egen if_sin_to_mar_N = sum(if_sin_to_mar) if droppout == 0 // not sure if this helps? 
gen timeline_sin_mar = .                       
replace timeline_sin_mar = 0 if if_sin_to_mar == 1 
bys id (wave): replace timeline_sin_mar = l.timeline_sin_mar + 1 if timeline_sin_mar == . 
bys id (nwave): replace timeline_sin_mar = l.timeline_sin_mar - 1 if timeline_sin_mar == .

Below is the detail on the marital status variable: marstat

Array