Hello Respected Experts,

Thanks a lot for previous help. @Carlo Lazzaro, sir you provided a Stata code to find duplicate director’s names in a variable. The code was . sort name year .duplicates tag name if year>=2007,gen(new_count)
Duplicates in terms of name

. replace new_count = new_count +1

Now I need the same Stata code with respect to industry. I need a new variable that lists the number of duplicates with respect to industry code. I need such a name count duplicate which restarts as the industry code changes, just like a wanted variable given as an example.

Thanks and regards,


year id name industry new_count wanted
2007 4 ali 27 3 1
2008 4 farman 27 2 1
2009 4 asad 27 1 1
2010 4 zahid 27 1 1
2007 8 khalid 28 1 1
2008 8 ali 28 3 2
2009 8 ali 28 3 2
2010 8 farman 28 2 1