I am working with a matched employer-employee dataset from Brazil in which each observation represents a pair worker-firm for some period and I would like to know for how many different firms a given worker has worked.
In particular, the dataset is like
year | week | id_worker | id_firm |
2017 | 1 | 17 | 25 |
2017 | 2 | 17 | 41 |
2017 | 3 | 17 | 19 |
2017 | 3 | 17 | 25 |
2017 | 4 | 17 | 53 |
2017 | 5 | 17 | 19 |
I would like to create a variable like 'number_of_firms_week'
year | week | id_worker | id_firm | number_of_firms_week |
2017 | 1 | 17 | 25 | 4 |
2017 | 2 | 17 | 41 | 4 |
2017 | 3 | 17 | 19 | 4 |
2017 | 3 | 17 | 25 | 4 |
2017 | 4 | 17 | 53 | 4 |
2017 | 5 | 17 | 19 | 4 |
Can you help me to find a solution for that?
Thank you very much!
Below I provide the code for importing the example dataset into Stata :
clear
input year week id_worker id_firm
2017 1 17 25
2017 2 17 41
2017 3 17 19
2017 3 17 25
2017 4 17 53
2017 5 17 19
end
Obs: I tried to use 'dataex' but I found it easier, in this case, to provide the 'importing code'.
0 Response to Finding the number of firms for which a given worker has worked - Matched employer-employee dataset
Post a Comment