Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Count number of periods with first firm after finding a job.

    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.

    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
    Cases, and say we count 6 periods:
    • 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.
    Last edited by Henry Strawforrd; 05 Aug 2022, 07:39.

  • #2
    Code:
    //  FIRST IDENTIFY THE APPROPRIATE START TIME AND ASSOCIATED EMPL_ID
    by id (t), sort: egen ref_time = min(cond(job_type == 1, t, .))
    by id (t): egen ref_empl_id = max(cond(t == ref_time, empl_id, .))
    
    //  COUNT UP TENURE WITH THAT EMPL_ID IN JOB TYPE 1 FROM THAT TIME ONWARD
    by id (t): egen wanted = total(t >= ref_time & job_type == 1 & empl_id == ref_empl_id)
    Added: You did not say what you want to do if an ID starts a type 1 job with an empl_id and subsequently continues with that same empl_id but job_type changes to 0 (with or without changing back to 1 after that). The code above assumes you do not want to count the times when job_type is 0 in this situation.

    I also assume that if, after starting a type 1 job with an empl_id, ID switches temporarily to another empl_id (with job_type 0 or 1) and then switches back to the first empl_id in a type 1 job, you want to count all of the time spent with empl_id in a type 1 job, notwithstanding the interlude with another employer.
    Last edited by Clyde Schechter; 05 Aug 2022, 09:38.

    Comment


    • #3
      Both assumptions are correct, and wonderful code thank you!

      Comment

      Working...
      X