I have a dataset wherein I have account number and "days past due" with every observation. For every account number, as soon as the "days past due" column hits a code like "DLQ3", I want to remove rest of the rows for that account (even if DLQ3 is the first observation for that account).
My dataset looks like:
Obs_month Acc_No OS_Bal Days_past_due
201005 2000000031 3572.68 NORM
201006 2000000031 4036.78 NORM
200810 2000000049 39741.97 NORM
200811 2000000049 38437.54 DLQ3
200812 2000000049 23923.98 DLQ1
200901 2000000049 35063.88 NORM
So, for account 2000000049, I want to remove all the rows post the date 200812 as now it's in default.
So in all, I want to see when the account hits DLQ3 and when it does I want to remove all the rows post the first DLQ3 observation.
What I tried was to subset the data with all DLQ3 observations and order the observation month in ascending order and getting an unique list of account number which have DLQ3 and their first month of hitting DLQ3. Post that I thought I could do some left_join with the orginal data and use ifelse but the flow is dicey.