Dear all,
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 from the same sector a given worker has worked.
In particular, the dataset is like
I would like to have other three new variables such as
where 'number_of_firms_sector' counts the number of different firms for which the worker has worked in a given 'sector', where sector \in {Manufacturing, Services, Commerce}.
Can you help to find a solution for that?
Thank you!
Code for importing:
clear
input year week id_worker id_firm str15 firm_sector
2017 1 17 25 "Services"
2017 2 17 41 "Manufacturing"
2017 3 17 19 "Commerce"
2017 3 17 25 "Services"
2017 4 17 53 "Services"
2017 5 17 19 "Commerce"
end
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 from the same sector a given worker has worked.
In particular, the dataset is like
year | week | id_worker | id_firm | firm_sector |
2017 | 1 | 17 | 25 | Services |
2017 | 2 | 17 | 41 | Manufacturing |
2017 | 3 | 17 | 19 | Manufacturing |
2017 | 3 | 17 | 25 | Services |
2017 | 4 | 17 | 53 | Services |
2017 | 5 | 17 | 19 | Manufacturing |
I would like to have other three new variables such as
year | week | id_worker | id_firm | firm_sector | number_of_firms_services | number_of_firms_manufacturing | number_of_firms_commerce |
2017 | 1 | 17 | 25 | Services | 2 | 1 | 1 |
2017 | 2 | 17 | 41 | Manufacturing | 2 | 1 | 1 |
2017 | 3 | 17 | 19 | Commerce | 2 | 1 | 1 |
2017 | 3 | 17 | 25 | Services | 2 | 1 | 1 |
2017 | 4 | 17 | 53 | Services | 2 | 1 | 1 |
2017 | 5 | 17 | 19 | Commerce | 2 | 1 | 1 |
where 'number_of_firms_sector' counts the number of different firms for which the worker has worked in a given 'sector', where sector \in {Manufacturing, Services, Commerce}.
Can you help to find a solution for that?
Thank you!
Code for importing:
clear
input year week id_worker id_firm str15 firm_sector
2017 1 17 25 "Services"
2017 2 17 41 "Manufacturing"
2017 3 17 19 "Commerce"
2017 3 17 25 "Services"
2017 4 17 53 "Services"
2017 5 17 19 "Commerce"
end
Comment