I want to count the number of periods within the next X periods, that a person stayed with the first firm after finding a job. The difficulty I am having is that I want to skip gaps, and also there is two types of jobs and I have to ignore one. So the standard spell counting did not work for me.
Here is an MWE with the important cases. I have panel data of individuals (id) periods (t) who either have a job (job=1) or not (job=0). There is two types of jobs, and I want to ignore the type for whom job_type=0. Employers are identified by empl_id.
Cases, and say we count 6 periods:
Here is an MWE with the important cases. I have panel data of individuals (id) periods (t) who either have a job (job=1) or not (job=0). There is two types of jobs, and I want to ignore the type for whom job_type=0. Employers are identified by empl_id.
Code:
input id t job job_type empl_id 1 1 0 . . 1 2 1 1 1 1 3 1 1 1 1 4 1 1 2 1 5 1 1 2 2 1 0 . . 2 2 0 . . 2 3 1 0 2 2 4 1 1 3 2 5 1 1 3 2 6 1 1 3 3 1 0 . . 3 2 1 1 4 3 3 1 1 4 3 4 0 . . 3 5 1 1 4 3 6 1 1 4 end
- Person with id 1 got a job in period 2, this is the right type so the first firm is firm_id = 1. They stayed for two period with this firm and then switched firm. Therefore, the resulting number of periods as first firm should be 2.
- Person with id 2 got a job in period 3, however this job was type=0 so we don't count it. But in period 4 the job was right, and afterwards the person stay with that firm for three periods. So the resulting counter should be 3 here
- Person got a correct job in period 2. We count two periods with that, and then comes the difficulty. There is a break in between but then the person continued with that firm. I need the variable to ignore this break and give a total of 4 periods.

Comment