Sorry if the title is confusing, I have a hard to articulating the problem in a short title. Currently, my data set has a mix of healthcare visits that are primary care(pc) and pain specialists (ps). I am able to identify the FIRST primary care visit for each patient. What I want to do is then identify the next pain specialist visit, in actual time, for that specific patient. I can either delete all pain visits that are before that primary care visit or just create a dummy variable. I do not know how to code for this at all. Below I have the primary care (pc) visit that I already have identified and serves as the starting point (by date) to identify the next pain specialist visit (ps). Example: ID visit date keep 1 ps 11/23/19 0 1 ps 12/1/19 0 1 pc 12/15/19 1* 1 ps 1/3/20 1 2 ps 5/23/19 0 2 pc 6/25/19 1* 2 ps 7/3/19 1 3 pc 3/21/20 1 3 ps 4/2/20 1 * already identified
... View more