Hello,

I want to define a variable conditioned after a certain range of another variable.

For instance, each id has a binary variable 'served' which indicates whether the id was served by the system.

Each id also has exit_month when they exited the system.

Here, I want to find the month they returned after they exited.

Code:
ID     month          served       exit_month         return_month
1       2015m9                1             .           .
1       2015m10              1             .           .
1       2015m11              0          2015m11          .
1       2015m12              0             .             .
1       2016m1                1             .         2016m1
1       2016m2                1             .           .
1       2016m3                0         2016m3         .
1       2016m4                1            .             2016m4
2      2015m9                 1            .                .
2      2015m10               0           2015m10    .
...
I tried using -inrange -, but did not work. Is there a way where I can set the range for exit_month?

gen return_month = "between first exit_month and next exit month"?

Thank you!