Hello everyone.
I am looking to do a survival time analysis of unemployment periods, where a subject "fails" by getting a job. I am currently struggling with getting stset (stata version 17.0) to work properly. My problem is, that each subject may have multiple unemployment periods while they are under observation (meaning multiple "exposures" to risk, and multiple failures per subject). I also have subjects that are not exposed to risk at all.
Variables of interest:
pnr : Person identifier
aar : Calendar year
cstate : Identifies occipational state (E = employed, U = unemployed, N = also unemployed )
Start & slut : Marks the beginning and end of the observational period.
Identifying risk exposure and failure.
I have tried using code to identify the beginning and end of unemployment spells(representing exposure to risk and failure). It's essentially saying that an unemployment spell begins if an employed person becomes unemployed in the following observation (and vice versa).
by pnr: gen byte uspellbegin = (cstate == "E") & ((cstate[_n+1] == "U") | (cstate[_n+1] == "N"))
by pnr: gen byte uspellend = ((cstate == "U") | (cstate == "N")) & (cstate[_n+1] == "E")
This part of the code appears to be working relatively well, but i am not sure if it is the correct strategy?
st-setting data
I used the command " stset slut, id(pnr) failure(uspellend) origin(uspellbegin) "
I have included an example of the code using dataex.
PNR: 000009369402
This person is not supposed to be included in the analysis. There is no observations where "uspellbegin=1, so i don't understand why _st=1 for all of the observations.
PNR: 000016765643
This person has three employed periods before becoming unemployed. Based on my understanding, these periods shouldn't be counted, because the subject hasn't yet been exposed to risk. Also, after the first "failure" (uspellend), the subject is removed from the observation pool, even though they have more unemployment spells ind the future.
I welcome any and all advice and feedback
I am looking to do a survival time analysis of unemployment periods, where a subject "fails" by getting a job. I am currently struggling with getting stset (stata version 17.0) to work properly. My problem is, that each subject may have multiple unemployment periods while they are under observation (meaning multiple "exposures" to risk, and multiple failures per subject). I also have subjects that are not exposed to risk at all.
Variables of interest:
pnr : Person identifier
aar : Calendar year
cstate : Identifies occipational state (E = employed, U = unemployed, N = also unemployed )
Start & slut : Marks the beginning and end of the observational period.
Identifying risk exposure and failure.
I have tried using code to identify the beginning and end of unemployment spells(representing exposure to risk and failure). It's essentially saying that an unemployment spell begins if an employed person becomes unemployed in the following observation (and vice versa).
by pnr: gen byte uspellbegin = (cstate == "E") & ((cstate[_n+1] == "U") | (cstate[_n+1] == "N"))
by pnr: gen byte uspellend = ((cstate == "U") | (cstate == "N")) & (cstate[_n+1] == "E")
This part of the code appears to be working relatively well, but i am not sure if it is the correct strategy?
st-setting data
I used the command " stset slut, id(pnr) failure(uspellend) origin(uspellbegin) "
I have included an example of the code using dataex.
PNR: 000009369402
This person is not supposed to be included in the analysis. There is no observations where "uspellbegin=1, so i don't understand why _st=1 for all of the observations.
PNR: 000016765643
This person has three employed periods before becoming unemployed. Based on my understanding, these periods shouldn't be counted, because the subject hasn't yet been exposed to risk. Also, after the first "failure" (uspellend), the subject is removed from the observation pool, even though they have more unemployment spells ind the future.
I welcome any and all advice and feedback

Code:
* Example generated by -dataex-. For more info, type help dataex clear input str12 pnr double aar str10 cstate double(start slut) byte(uspellbegin uspellend) int(_t0 _t) byte(_d _st) "000009369402" 1985 "E" 3 54 0 0 0 54 0 1 "000009369402" 1986 "E" 55 106 0 0 54 106 0 1 "000009369402" 1987 "E" 107 159 0 0 106 159 0 1 "000009369402" 1988 "E" 160 211 0 0 159 211 0 1 "000009369402" 1989 "E" 212 263 0 0 211 263 0 1 "000009369402" 1990 "E" 264 315 0 0 263 315 0 1 "000009369402" 1991 "E" 316 367 0 0 315 367 0 1 "000016765643" 1985 "E" 3 54 0 0 0 54 0 1 "000016765643" 1986 "E" 55 106 0 0 54 106 0 1 "000016765643" 1987 "E" 107 159 1 0 106 159 0 1 "000016765643" 1988 "U" 160 163 0 1 159 163 1 1 "000016765643" 1988 "E" 164 211 0 0 . . . 0 "000016765643" 1989 "E" 212 263 0 0 . . . 0 "000016765643" 1990 "E" 264 306 1 0 . . . 0 "000016765643" 1990 "U" 307 311 0 1 . . . 0 "000016765643" 1990 "E" 312 315 0 0 . . . 0 "000016765643" 1991 "E" 316 323 1 0 . . . 0 "000016765643" 1991 "U" 324 328 0 1 . . . 0 "000016765643" 1991 "E" 329 367 0 0 . . . 0 "000019726141" 1985 "E" 3 46 1 0 0 46 0 1 "000019726141" 1985 "N" 47 54 0 1 46 54 1 1 "000019726141" 1986 "E" 55 106 0 0 . . . 0 "000019726141" 1987 "E" 107 150 1 0 . . . 0 "000019726141" 1987 "N" 151 159 0 1 . . . 0 "000019726141" 1988 "E" 160 211 0 0 . . . 0 "000019726141" 1989 "E" 212 263 0 0 . . . 0 "000019726141" 1990 "E" 264 315 0 0 . . . 0 "000019726141" 1991 "E" 316 367 0 0 . . . 0 "000021709549" 1985 "E" 3 54 0 0 0 54 0 1 "000021709549" 1986 "E" 55 106 0 0 54 106 0 1 "000021709549" 1987 "E" 107 159 0 0 106 159 0 1 "000021709549" 1988 "E" 160 211 0 0 159 211 0 1 "000021709549" 1989 "E" 212 263 0 0 211 263 0 1 "000021709549" 1990 "E" 264 315 0 0 263 315 0 1 "000021709549" 1991 "E" 316 367 0 0 315 367 0 1 "000021709549" 1992 "E" 368 420 0 0 367 420 0 1 "000021709549" 1993 "E" 421 472 0 0 420 472 0 1 "000021709549" 1994 "E" 473 524 0 0 472 524 0 1 "000021709549" 1995 "E" 525 576 0 0 524 576 0 1 "000021709549" 1996 "E" 577 628 0 0 576 628 0 1 "000021709549" 1997 "E" 629 680 0 0 628 680 0 1 "000021709549" 1998 "E" 681 733 0 0 680 733 0 1 "000021709549" 1999 "E" 734 785 0 0 733 785 0 1 "000023670701" 1985 "N" 3 54 0 0 0 54 0 1 "000023670701" 1986 "N" 55 106 0 0 54 106 0 1 "000023670701" 1987 "N" 107 159 0 0 106 159 0 1 "000023670701" 1988 "N" 160 211 0 0 159 211 0 1 "000023670701" 1989 "N" 212 263 0 0 211 263 0 1 "000023670701" 1990 "N" 264 315 0 0 263 315 0 1 "000023670701" 1991 "N" 316 367 0 0 315 367 0 1 "000028600706" 1985 "U" 3 54 0 0 0 54 0 1 "000028600706" 1986 "U" 55 106 0 0 54 106 0 1 "000028600706" 1987 "U" 107 119 0 0 106 119 0 1 "000028600706" 1987 "O" 120 159 0 0 119 159 0 1 "000028600706" 1988 "O" 160 211 0 0 159 211 0 1 "000028600706" 1989 "O" 212 263 0 0 211 263 0 1 "000028600706" 1990 "O" 264 315 0 0 263 315 0 1 "000028600706" 1991 "O" 316 367 0 0 315 367 0 1 "000029586941" 1985 "E" 3 54 0 0 0 54 0 1 "000029586941" 1986 "E" 55 106 0 0 54 106 0 1 "000029586941" 1987 "E" 107 159 0 0 106 159 0 1 "000029586941" 1988 "E" 160 211 0 0 159 211 0 1 "000029586941" 1989 "E" 212 263 0 0 211 263 0 1 "000029586941" 1990 "E" 264 315 0 0 263 315 0 1 "000029586941" 1991 "E" 316 367 0 0 315 367 0 1 "000030080404" 1985 "S" 3 54 0 0 0 54 0 1 "000030080404" 1986 "S" 55 106 0 0 54 106 0 1 "000030080404" 1987 "S" 107 159 0 0 106 159 0 1 "000030080404" 1988 "S" 160 211 0 0 159 211 0 1 "000030080404" 1989 "S" 212 263 0 0 211 263 0 1 "000030080404" 1990 "S" 264 315 0 0 263 315 0 1 "000030080404" 1991 "S" 316 367 0 0 315 367 0 1 "000030570281" 1985 "E" 25 54 0 0 0 54 0 1 "000030570281" 1986 "E" 55 56 0 0 54 56 0 1 "000030570281" 1986 "E" 57 106 0 0 56 106 0 1 "000030570281" 1987 "E" 107 159 0 0 106 159 0 1 "000030570281" 1988 "E" 160 211 0 0 159 211 0 1 "000030570281" 1989 "E" 212 263 0 0 211 263 0 1 "000030570281" 1990 "E" 264 315 0 0 263 315 0 1 "000030570281" 1991 "E" 316 367 0 0 315 367 0 1 "000031559345" 1985 "N" 3 54 0 1 0 54 1 1 "000031559345" 1986 "E" 55 98 0 0 . . . 0 "000031559345" 1986 "E" 99 106 0 0 . . . 0 "000031559345" 1987 "E" 107 115 0 0 . . . 0 "000031559345" 1987 "E" 116 159 1 0 . . . 0 "000031559345" 1988 "N" 160 185 0 0 . . . 0 "000031559345" 1988 "U" 186 211 0 0 . . . 0 "000031559345" 1989 "U" 212 214 0 0 . . . 0 "000031559345" 1989 "N" 215 218 0 0 . . . 0 "000031559345" 1989 "U" 219 263 0 0 . . . 0 "000031559345" 1990 "U" 264 266 0 0 . . . 0 "000031559345" 1990 "N" 267 270 0 0 . . . 0 "000031559345" 1990 "U" 271 278 0 0 . . . 0 "000031559345" 1990 "N" 279 280 0 0 . . . 0 "000031559345" 1990 "U" 281 282 0 1 . . . 0 "000031559345" 1990 "E" 283 315 1 0 . . . 0 "000031559345" 1991 "N" 316 322 0 0 . . . 0 "000031559345" 1991 "U" 323 367 0 0 . . . 0 "000031559345" 1992 "U" 368 369 0 0 . . . 0 "000031559345" 1992 "N" 370 372 0 0 . . . 0 end