Hello, So sorry for poor explanation! This is the result that I want to have! The column DIF records the sum of difference between companies and their rivals who has higher values of VAR1. For example, Company 002 is the best in industry 4 (highest values of VAR1 in each year), thus I don't consider the differences in Var between 002 and other companies in industry 4 (001 and 003). Therefore, DIF of 002 is 0. Company 004 does not have rivals in industry 5, therefore DIF is 0 as well. Company 001 has only 1 "better" rival (higher value of VAR1) in industry 4, which is 002, therefore DIF records the difference in VAR1 between 001 and 002. Meanwhile, 003 has two "better" rivals in industry 4, thus therefore DIF records the THE SUM of differences in VAR1 between 001 and 003, and between 002 and 003.

... View more