Maybe the case is best illustrated with an example.
The two codes generate different results for employee 1 in 2000, which i think should not be coded as being a specialist. Only the second code does this properly.
Another case to consider is employee 2. Is someone a specialist when returning to the same firm after working in another firm from another industry? If so, you will need different code.
Code:
clear input employeeID Year IndustryCode companyId 1 2000 20 1 1 2001 20 2 1 2002 20 1 2 2000 20 1 2 2001 30 3 2 2002 20 1 end bysort employeeID IndustryCode (Year): gen tag = companyId != companyId[_n-1] & _n > 1 * first code bysort employeeID companyId: egen probably_not_wanted = max(tag) * second code bysort employeeID IndustryCode (Year): gen wanted = sum(tag) >= 1 sort employeeID Year list, noobs abbr(20) sepby(employeeID) +-----------------------------------------------------------------------------------+ | employeeID Year IndustryCode companyId tag probably_not_wanted wanted | |-----------------------------------------------------------------------------------| | 1 2000 20 1 0 1 0 | | 1 2001 20 2 1 1 1 | | 1 2002 20 1 1 1 1 | |-----------------------------------------------------------------------------------| | 2 2000 20 1 0 0 0 | | 2 2001 30 3 0 0 0 | | 2 2002 20 1 0 0 0 | +-----------------------------------------------------------------------------------+
Another case to consider is employee 2. Is someone a specialist when returning to the same firm after working in another firm from another industry? If so, you will need different code.
Comment