Hey Stata Community,

I need to split every job episode according to calendar years (rrdat dataset; monthly data starting from 1900) and then merge to this yearly subepisode the unemployment rate (UE dataset) of this particular year.

Here are the steps I have done so far:

gen start = 0
gen event = tfin != ti

gen tstart1 = 1900 + tstart/12
gen tstart2 = int(tstart1)

gen tfin1 = 1900 + tfin/12
gen tfin2 = int(tfin1)
tab tfin2 in 1/50

gen duration = tfin2 - tstart2 + 1
tab duration

gen newid = _n

stset duration, f(event) id(newid)
expand duration
by newid, sort: replace start = duration[_n - 1] if newid == newid[_n-1]
by newid, sort: gen year = tstart2[_n-1]+ _n-1 if newid==newid[_n-1]
replace year = tstart2 if year==.

However, after I merge the datasets and run stset duration, f(event) id(newid), Stata gives me a probable error.

Could you please advise what is wrong and how this can be fixed?

I appreciate any help!