Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Selecting a peer group for comparison

    Dear all,

    I have a question that I think should be pretty straightforward for some of the power users on this forum. Research shows that in evaluating their performance, firms compare themselves to their closest peers not their entire industry. So, I need to select 5 firms that are closest to the focal firm in size. My data consists of the following columns: firm_code, country_code, industry_code, year, total_assets, net income (among others). I generated a rank for each firm in terms of total assets within each country, industry and year, now I want to compute the performance of peer group (so, 5 closest firms in size). If a firm is ranked 1, it could be firms ranked 2-6, but if a firm is ranked 21, it could be firms ranked above and below (firms closest in size). What would be the Stata command to identify/ compute? Thanks so much for your help in advance!

    Best,
    Pete

  • #2
    You want to collapse the dataset using your defined group, form pairwise combinations of the dataset and itself using cross and calculate the absolute difference. Here is an illustration using the Grunfeld dataset, where we want to match firms with the closest value of investment.

    Code:
    webuse grunfeld, clear
    collapse invest, by(company)
    preserve
    list, sep(0)
    rename (company invest) (match invest_m)
    tempfile match
    save `match'
    restore
    cross using `match'
    gen abs_diff= abs(invest-invest_m) if company!=match
    bys company (abs_diff): keep if _n<=5
    sort company match
    list, sepby(company)
    Res.:

    Code:
    . list, sep(0)
    
         +-------------------+
         | company    invest |
         |-------------------|
      1. |       1    608.02 |
      2. |       2   410.475 |
      3. |       3    102.29 |
      4. |       4   86.1235 |
      5. |       5   61.8025 |
      6. |       6    55.411 |
      7. |       7   47.5955 |
      8. |       8   42.8915 |
      9. |       9    41.889 |
     10. |      10    3.0845 |
         +-------------------+
    
    
    
    . list, sepby(company)
    
         +-------------------------------------------------+
         | company    invest   match   invest_m   abs_diff |
         |-------------------------------------------------|
      1. |       1    608.02       2    410.475    197.545 |
      2. |       1    608.02       3     102.29     505.73 |
      3. |       1    608.02       4    86.1235   521.8965 |
      4. |       1    608.02       5    61.8025   546.2175 |
      5. |       1    608.02       6     55.411    552.609 |
         |-------------------------------------------------|
      6. |       2   410.475       1     608.02    197.545 |
      7. |       2   410.475       3     102.29    308.185 |
      8. |       2   410.475       4    86.1235   324.3515 |
      9. |       2   410.475       5    61.8025   348.6725 |
     10. |       2   410.475       6     55.411    355.064 |
         |-------------------------------------------------|
     11. |       3    102.29       4    86.1235    16.1665 |
     12. |       3    102.29       5    61.8025    40.4875 |
     13. |       3    102.29       6     55.411     46.879 |
     14. |       3    102.29       7    47.5955    54.6945 |
     15. |       3    102.29       8    42.8915    59.3985 |
         |-------------------------------------------------|
     16. |       4   86.1235       3     102.29    16.1665 |
     17. |       4   86.1235       5    61.8025     24.321 |
     18. |       4   86.1235       6     55.411    30.7125 |
     19. |       4   86.1235       7    47.5955     38.528 |
     20. |       4   86.1235       8    42.8915     43.232 |
         |-------------------------------------------------|
     21. |       5   61.8025       4    86.1235     24.321 |
     22. |       5   61.8025       6     55.411   6.391502 |
     23. |       5   61.8025       7    47.5955     14.207 |
     24. |       5   61.8025       8    42.8915     18.911 |
     25. |       5   61.8025       9     41.889    19.9135 |
         |-------------------------------------------------|
     26. |       6    55.411       4    86.1235    30.7125 |
     27. |       6    55.411       5    61.8025   6.391502 |
     28. |       6    55.411       7    47.5955   7.815498 |
     29. |       6    55.411       8    42.8915    12.5195 |
     30. |       6    55.411       9     41.889     13.522 |
         |-------------------------------------------------|
     31. |       7   47.5955       4    86.1235     38.528 |
     32. |       7   47.5955       5    61.8025     14.207 |
     33. |       7   47.5955       6     55.411   7.815498 |
     34. |       7   47.5955       8    42.8915   4.704002 |
     35. |       7   47.5955       9     41.889   5.706501 |
         |-------------------------------------------------|
     36. |       8   42.8915       5    61.8025     18.911 |
     37. |       8   42.8915       6     55.411    12.5195 |
     38. |       8   42.8915       7    47.5955   4.704002 |
     39. |       8   42.8915       9     41.889   1.002499 |
     40. |       8   42.8915      10     3.0845     39.807 |
         |-------------------------------------------------|
     41. |       9    41.889       5    61.8025    19.9135 |
     42. |       9    41.889       6     55.411     13.522 |
     43. |       9    41.889       7    47.5955   5.706501 |
     44. |       9    41.889       8    42.8915   1.002499 |
     45. |       9    41.889      10     3.0845    38.8045 |
         |-------------------------------------------------|
     46. |      10    3.0845       5    61.8025     58.718 |
     47. |      10    3.0845       6     55.411    52.3265 |
     48. |      10    3.0845       7    47.5955     44.511 |
     49. |      10    3.0845       8    42.8915     39.807 |
     50. |      10    3.0845       9     41.889    38.8045 |
         +-------------------------------------------------+
    
    .

    Comment


    • #3
      Thank you Andrew. That's exactly what I needed.

      Comment


      • #4
        Hi Andrew. I used the modified code for matching, but it seems that two of the grouping variables are being ignored and it seems to be matching just on the asset size. Basically, I am trying to match firms against peers in the same country and industry. Here is my code: (where ccode is country code and indcode is industry code).

        set more off
        collapse assets, by(ccode indcode ProjID)
        preserve
        list, sep(0)
        rename (ProjID assets) (match assets_m)
        tempfile match
        save `match'
        restore
        cross using `match'
        gen abs_diff= abs(assets - assets_m) if ProjID!=match
        bys ProjID (abs_diff): keep if _n<=5
        sort ProjID match
        list, sepby(ProjID)

        I tried adding ccode and indcode in other parts of the algorithm, but couldn't get it to work. Any advice on what I am doing wrong / what I need to do? Many thanks for your help!
        Last edited by Peter Suntan; 08 Jul 2021, 07:07.

        Comment


        • #5
          If you are forming pairwise combinations within groups, use joinby in place of cross. I modify the example in #2 to have 2 industries, and I match firms within industries.

          Code:
          webuse grunfeld, clear
          gen industry=cond(company<=5, 1, 2)
          collapse invest, by(company industry)
          preserve
          list, sep(0)
          rename (company invest) (match invest_m)
          tempfile match
          save `match'
          restore
          joinby industry using `match'
          drop if company==match
          sort company industry match
          Res.:

          Code:
          . l, sepby(company)
          
               +-------------------------------------------------+
               | company   industry    invest   match   invest_m |
               |-------------------------------------------------|
            1. |       1          1    608.02       2    410.475 |
            2. |       1          1    608.02       3     102.29 |
            3. |       1          1    608.02       4    86.1235 |
            4. |       1          1    608.02       5    61.8025 |
               |-------------------------------------------------|
            5. |       2          1   410.475       1     608.02 |
            6. |       2          1   410.475       3     102.29 |
            7. |       2          1   410.475       4    86.1235 |
            8. |       2          1   410.475       5    61.8025 |
               |-------------------------------------------------|
            9. |       3          1    102.29       1     608.02 |
           10. |       3          1    102.29       2    410.475 |
           11. |       3          1    102.29       4    86.1235 |
           12. |       3          1    102.29       5    61.8025 |
               |-------------------------------------------------|
           13. |       4          1   86.1235       1     608.02 |
           14. |       4          1   86.1235       2    410.475 |
           15. |       4          1   86.1235       3     102.29 |
           16. |       4          1   86.1235       5    61.8025 |
               |-------------------------------------------------|
           17. |       5          1   61.8025       1     608.02 |
           18. |       5          1   61.8025       2    410.475 |
           19. |       5          1   61.8025       3     102.29 |
           20. |       5          1   61.8025       4    86.1235 |
               |-------------------------------------------------|
           21. |       6          2    55.411       7    47.5955 |
           22. |       6          2    55.411       8    42.8915 |
           23. |       6          2    55.411       9     41.889 |
           24. |       6          2    55.411      10     3.0845 |
               |-------------------------------------------------|
           25. |       7          2   47.5955       6     55.411 |
           26. |       7          2   47.5955       8    42.8915 |
           27. |       7          2   47.5955       9     41.889 |
           28. |       7          2   47.5955      10     3.0845 |
               |-------------------------------------------------|
           29. |       8          2   42.8915       6     55.411 |
           30. |       8          2   42.8915       7    47.5955 |
           31. |       8          2   42.8915       9     41.889 |
           32. |       8          2   42.8915      10     3.0845 |
               |-------------------------------------------------|
           33. |       9          2    41.889       6     55.411 |
           34. |       9          2    41.889       7    47.5955 |
           35. |       9          2    41.889       8    42.8915 |
           36. |       9          2    41.889      10     3.0845 |
               |-------------------------------------------------|
           37. |      10          2    3.0845       6     55.411 |
           38. |      10          2    3.0845       7    47.5955 |
           39. |      10          2    3.0845       8    42.8915 |
           40. |      10          2    3.0845       9     41.889 |
               +-------------------------------------------------+

          Comment


          • #6
            Thx Andrew. In the above example, I don't need "gen industry" since I already have industry, but I need to find 5 best matches (nearest in assets) from a varying number of firms in the industry (which could be none other to 100s). I am not sure I see if this is the case in the code above.

            Comment


            • #7
              The above code just illustrates the pairing, you need to append the rest of the code. The sample size is limiting here as each firm is matched with 4 other firms. Say I needed the closest 2 in terms of the absolute value of invest, then:

              Code:
              webuse grunfeld, clear
              gen industry=cond(company<=5, 1, 2)
              collapse invest, by(company industry)
              preserve
              list, sep(0)
              rename (company invest) (match invest_m)
              tempfile match
              save `match'
              restore
              joinby industry using `match'
              gen abs_diff= abs(invest-invest_m) if company!=match
              bys company (abs_diff): keep if _n<=2
              sort company industry match
              list, sepby(company)
              Res.:

              Code:
              . list, sepby(company)
              
                   +------------------------------------------------------------+
                   | company   industry    invest   match   invest_m   abs_diff |
                   |------------------------------------------------------------|
                1. |       1          1    608.02       2    410.475    197.545 |
                2. |       1          1    608.02       3     102.29     505.73 |
                   |------------------------------------------------------------|
                3. |       2          1   410.475       1     608.02    197.545 |
                4. |       2          1   410.475       3     102.29    308.185 |
                   |------------------------------------------------------------|
                5. |       3          1    102.29       4    86.1235    16.1665 |
                6. |       3          1    102.29       5    61.8025    40.4875 |
                   |------------------------------------------------------------|
                7. |       4          1   86.1235       3     102.29    16.1665 |
                8. |       4          1   86.1235       5    61.8025     24.321 |
                   |------------------------------------------------------------|
                9. |       5          1   61.8025       3     102.29    40.4875 |
               10. |       5          1   61.8025       4    86.1235     24.321 |
                   |------------------------------------------------------------|
               11. |       6          2    55.411       7    47.5955   7.815498 |
               12. |       6          2    55.411       8    42.8915    12.5195 |
                   |------------------------------------------------------------|
               13. |       7          2   47.5955       8    42.8915   4.704002 |
               14. |       7          2   47.5955       9     41.889   5.706501 |
                   |------------------------------------------------------------|
               15. |       8          2   42.8915       7    47.5955   4.704002 |
               16. |       8          2   42.8915       9     41.889   1.002499 |
                   |------------------------------------------------------------|
               17. |       9          2    41.889       7    47.5955   5.706501 |
               18. |       9          2    41.889       8    42.8915   1.002499 |
                   |------------------------------------------------------------|
               19. |      10          2    3.0845       8    42.8915     39.807 |
               20. |      10          2    3.0845       9     41.889    38.8045 |
                   +------------------------------------------------------------+
              
              .

              Comment

              Working...
              X