I would like to define an employee (identified by employee ID) as an industry specialist (equal to 1) if the firm where s/he an employee shares the same industry code (identified by two digits) with at least one firm in his employment history. A worker in the year 2004, for example, would be an industry specialist if s/he worked in a firm that shares the same industry code prior to 2004 (and of course not after). Therefore, the employee identified as 12342 is an industry specialist in 2002 (and not in 1999) as shown in the following table:
companyId Year employeeID IndustryCode
GB12345678910 2002 12342 20
GB00000000000 2003 45674567 30
GB23452345234 2004 12342 40
GB52349088454 2005 45674567 20
GB5345893748 2006 6546456 10
GB34534534500 1999 12342 20
GB0977709709 2000 1234454 30
GB09304570394 2001 6546456 10
Bear in mind that an employee might not be an industry specialist in a particular year but might be so in the following years. I have a large number of observations and I am wondering if there are any commands to create such dummy variables in Stata.