I have a employer-employee panel dataset at quarter frequency. The data includes some irregularities which I want to document to draw a picture of the labor market dynamics in that sector. In data, there exist workers who work for one firm for some day, and pass to another firm within the same quarter. I want to create indicator variables to tag how many times a particular worker has changed job/firm (i) within same period t and (ii) from t-1 to t and (iii) for how many quarters she stayed unemployed (missing mday in my data). I figured out the third one in a long way but could not manage the first two.
In the data mday refers to number of working days, wid is worker identity and firmid is the identity of the firm and id refers to panel id for each (worker,firm) group.
My data looks like the following:
Worker 1 has worked for Firm 30 and Firm 20 in 2015q4, which is different than the firmshe worked in 2015q3(firm 10). So for 2015q4 my indicator variable should be 1 for both observations at 2015q4. But I could not manage so far.
I tried the following to tag the periods t when a worker started to work in a different firm than t-1.
But this does not solve my problem. For ex. this code results firmchange=1 for wid=1 and date= 2017q2, but since the worker worked for firm 10 in both 2017q1 and 2017q2, that should not be tagged as a firm change at 2017q2.
To be more precise data for worker 1 looks like the following:
Any help is appreciated, thanks in advance.
In the data mday refers to number of working days, wid is worker identity and firmid is the identity of the firm and id refers to panel id for each (worker,firm) group.
My data looks like the following:
Code:
Example generated by -dataex-. To install: ssc install dataex clear input float date byte(wid firmid) long id double mday
2015q1 1 40 12 . 2015q1 1 10 1 20 2015q1 1 50 15 . 2015q1 1 20 4 8 2015q1 1 30 8 . 2015q2 1 10 1 30 2015q2 1 30 8 . 2015q2 1 20 4 . 2015q2 1 40 12 . 2015q2 1 50 15 . 2015q3 1 20 4 . 2015q3 1 50 15 . 2015q3 1 30 8 . 2015q3 1 10 1 30 2015q3 1 40 12 . 2015q4 1 30 8 10 2015q4 1 20 4 20 2015q4 1 50 15 . 2015q4 1 10 1 . 2015q4 1 40 12 . 2016q1 1 40 12 . 2016q1 1 30 8 . 2016q1 1 50 15 . 2016q1 1 20 4 . 2016q1 1 10 1 . 2016q2 1 40 12 . 2016q2 1 20 4 . 2016q2 1 50 15 . 2016q2 1 10 1 . 2016q2 1 30 8 . 2016q3 1 50 15 . 2016q3 1 20 4 . 2016q3 1 40 12 . 2016q3 1 10 1 . 2016q3 1 30 8 . 2016q4 1 10 1 1 2016q4 1 40 12 . 2016q4 1 30 8 . 2016q4 1 50 15 10 2016q4 1 20 4 . 2017q1 1 40 12 . 2017q1 1 20 4 . 2017q1 1 50 15 . 2017q1 1 10 1 30 2017q1 1 30 8 . 2017q2 1 10 1 15 2017q2 1 30 8 . 2017q2 1 50 15 . 2017q2 1 20 4 13 2017q2 1 40 12 4 2017q3 1 50 15 . 2017q3 1 30 8 . 2017q3 1 20 4 15 2017q3 1 10 1 15 2017q3 1 40 12 . 2017q4 1 30 8 . 2017q4 1 40 12 . 2017q4 1 50 15 . 2017q4 1 20 4 20 2017q4 1 10 1 11 2015q1 2 30 9 31 2015q1 2 40 13 . 2015q2 2 30 9 31 2015q2 2 40 13 . 2015q3 2 30 9 31 2015q3 2 40 13 . 2015q4 2 40 13 . 2015q4 2 30 9 31 2016q1 2 40 13 . 2016q1 2 30 9 31 2016q2 2 30 9 31 2016q2 2 40 13 . 2016q3 2 40 13 . 2016q3 2 30 9 . 2016q4 2 40 13 31 2016q4 2 30 9 . 2017q1 2 40 13 31 2017q1 2 30 9 . 2017q2 2 30 9 . 2017q2 2 40 13 31 2017q3 2 40 13 31 2017q3 2 30 9 . 2017q4 2 30 9 . 2017q4 2 40 13 31 2015q1 3 40 14 . 2015q1 3 60 17 . 2015q1 3 10 2 25 2015q1 3 50 16 . 2015q1 3 30 10 5 2015q1 3 20 5 . 2015q2 3 50 16 . 2015q2 3 60 17 . 2015q2 3 20 5 . 2015q2 3 10 2 30 2015q2 3 30 10 . 2015q2 3 40 14 . 2015q3 3 30 10 . 2015q3 3 60 17 . 2015q3 3 50 16 . 2015q3 3 20 5 . end format %tq date
I tried the following to tag the periods t when a worker started to work in a different firm than t-1.
Code:
[bysort wid date: gen timechange =1 if date!=date[_n-1] &mday!=. replace timechange=1 if date==date[_n-1] &mday!=. //I planned this timechange variable to show the times the worker is actively working bysort wid date: gen firmchange=1 if firmid != firmid[_n-1] & timechange==1
But this does not solve my problem. For ex. this code results firmchange=1 for wid=1 and date= 2017q2, but since the worker worked for firm 10 in both 2017q1 and 2017q2, that should not be tagged as a firm change at 2017q2.
To be more precise data for worker 1 looks like the following:
|
Comment