cpf sep_month hire_month hire_year sep_day hire_date sep_date
4 123 4 2 2012 1 2012-02-01 2013-04-01
5 123 0 4 2013 1 2013-04-01 <NA>
6 122 10 9 2012 1 2012-09-01 2013-10-01
7 122 0 12 2013 1 2013-12-01 <NA>
structure(list(cpf = c(123L, 123L, 122L, 122L), sep_month = c(4L,
0L, 10L, 0L), hire_month = c(2L, 4L, 9L, 12L), hire_year = c(2012L,
2013L, 2012L, 2013L), sep_day = c(1L, 1L, 1L, 1L), hire_date = structure(c(15371,
15796, 15584, 16040), class = "Date"), sep_date = structure(c(15796,
NA, 15979, NA), class = "Date")), row.names = 4:7, class = "data.frame")
In my dataset, each row is a job contract. I want to see the difference in months between sep_date and hire_date across different rows for the same CPF (identifier). For example, individual 123 separated from its job on 2013-04. On the following row, he was hired (under a different contract/job) on 2013-04. My goal is to create a dummy equal to 1 for individuals who separated from a contract and found a job in the same or following month. That would be the case for individual 123, but not for individual 122.
I appreciate any help.