Announcement

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

  • How to calculate competition (herfindahl-hirschman index)?

    Hi everyone,
    I am trying to identify how competitive the area (zip codes) is. I have the market shares of organizations across zip codes.
    The HHI is calculated by squaring the market share of each organization in the area.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str5 zipcode float market_share
    "00601"  94.93433
    "00601" 3.7898686
    "00601"  .3377111
    "00601"  .9380863
    "00602"  93.81937
    "00602"  4.809576
    "00602" 1.3710555
    "00603" 1.3475177
    "00603"  24.89362
    "00603" 15.531915
    "00603"  56.80851
    "00603" 1.4184397
    "00605" 37.735847
    "00605" 18.867924
    "00605"  43.39622
    "00606" 19.980925
    "00606"  80.01907
    "00610"  66.85678
    "00610"  33.14322
    "00611" 13.064133
    "00611"  86.93587
    "00612"  .4781997
    "00612"  7.735584
    "00612"  .8720112
    "00612"  63.26301
    "00612"  8.579466
    "00612" 15.583685
    "00612" 2.2503517
    "00612" 1.2376934
    "00613"  16.37931
    "00613"  70.97701
    "00613" 12.643678
    "00614"  17.28972
    "00614"  72.66355
    "00614"  10.04673
    "00616"  5.148515
    "00616"  47.92079
    "00616" 12.871287
    "00616" 34.059406
    "00617"  .3344968
    "00617"  .9307737
    "00617"  .8726004
    "00617"   7.35893
    "00617"  89.86329
    "00617"  .6399069
    "00622"       100
    "00623"       100
    "00624"   .375728
    "00624"  98.60981
    "00624"  .3193688
    "00624"  .6950967
    "00627"  78.20222
    "00627" 17.513758
    "00627" .59350383
    "00627" .22661056
    "00627"  3.463904
    "00631"  91.39151
    "00631"  8.608491
    "00637"  4.571429
    "00637"  95.42857
    "00638"  4.499487
    "00638"  87.99648
    "00638" 2.1984465
    "00638"  1.568225
    "00638"  3.737359
    "00641" 2.0793223
    "00641"  1.347709
    "00641"  88.21717
    "00641" 4.3896804
    "00641"  .9241433
    "00641" 3.0419714
    "00646"  71.39507
    "00646" 2.5791326
    "00646"  3.048066
    "00646"  2.344666
    "00646" 14.771395
    "00646"  5.861665
    "00647"       100
    "00650"   .458907
    "00650" 1.2828536
    "00650"  75.86566
    "00650" 22.392574
    "00652" 3.4552846
    "00652" 18.495935
    "00652" 10.162601
    "00652"  67.88618
    "00653"  1.978022
    "00653"  98.02198
    "00656"  68.90511
    "00656"  5.839416
    "00656" 25.255474
    "00659" 17.126081
    "00659"  79.79899
    "00659"   .457757
    "00659"  .4876107
    "00659" 2.1295652
    "00660"       100
    end
    Thank you for your help.

  • #2
    Gani:
    check if what follows does the trick (untested):
    Code:
    encode zipcode, g(num_zipcode)
    bysort num_zipcode: g wanted=sum(market_share^2)
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      It worked.
      Thank you so much for your help.

      Comment


      • #4
        Now I am reviewing the results, it seems like this formula didn't work as I needed.
        For example, when I look at the zip code area 00601, the HHI should be 9,027.8849

        display (0.33771107^2)+(94.934334^2)+(3.7898686^2)+(0.9380 8633^2)
        9027.8849

        That number should be the same for all the organizations located within a certain zip code.

        But the formula generated different HHI scores for each organization, within a zip code.

        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input float ID str5 zipcode float(market_share hhi)
        159 "00601"  .9380863   .880006
        115 "00601"  94.93433  9013.408
        117 "00601" 3.7898686 9027.7705
        135 "00601"  .3377111  9027.885
        128 "00602"  4.809576 23.132017
        127 "00602"  93.81937  8825.205
        135 "00602" 1.3710555  8827.085
        125 "00603" 1.3475177  1.815804
        135 "00603"  56.80851  3229.023
        127 "00603"  24.89362  3848.715
        159 "00603" 1.4184397  3850.727
        128 "00603" 15.531915  4091.967
        127 "00605" 37.735847  1423.994
        128 "00605" 18.867924 1779.9927
        135 "00605"  43.39622  3663.225
        115 "00606" 19.980925  399.2373
        128 "00606"  80.01907   6802.29
        128 "00610"  33.14322  1098.473
        127 "00610"  66.85678  5568.302
        135 "00611" 13.064133 170.67157
        159 "00611"  86.93587  7728.517
        134 "00612"  .8720112  .7604036
        141 "00612"  8.579466  74.36764
        135 "00612"  63.26301  4076.576
        159 "00612" 2.2503517   4081.64
        114 "00612"  .4781997  4081.869
        125 "00612"  7.735584  4141.708
        152 "00612" 15.583685  4384.559
        162 "00612" 1.2376934  4386.091
        125 "00613"  16.37931 268.28183
        135 "00613"  70.97701  5306.018
        152 "00613" 12.643678  5465.881
        152 "00614"  10.04673 100.93677
        135 "00614"  72.66355  5380.928
        125 "00614"  17.28972  5679.863
        141 "00616" 12.871287 165.67004
        152 "00616" 34.059406  1325.713
        125 "00616"  5.148515 1352.2205
        135 "00616"  47.92079 3648.6226
        134 "00617"  .9307737  .8663397
        125 "00617"  .3344968  .9782279
        135 "00617"  .8726004 1.7396593
        152 "00617"  89.86329   8077.15
        162 "00617"  .6399069   8077.56
        141 "00617"   7.35893  8131.714
        128 "00622"       100     10000
        128 "00623"       100     10000
        124 "00624"  .3193688 .10199641
        128 "00624"  .6950967  .5851559
        117 "00624"  98.60981 9724.4795
        115 "00624"   .375728  9724.621
        125 "00627"  78.20222  6115.588
        135 "00627" 17.513758   6422.32
        159 "00627"  3.463904  6434.318
        152 "00627" .22661056   6434.37
        141 "00627" .59350383  6434.722
        115 "00631"  91.39151  8352.408
        159 "00631"  8.608491  8426.515
        117 "00637"  4.571429  20.89796
        128 "00637"  95.42857  9127.511
        114 "00638"  4.499487  20.24538
        141 "00638" 2.1984465  25.07855
        162 "00638"  3.737359   39.0464
        134 "00638"  87.99648  7782.427
        152 "00638"  1.568225  7784.887
        125 "00641"  1.347709 1.8163193
        152 "00641"  .9241433   2.67036
        159 "00641" 3.0419714  11.92395
        135 "00641"  88.21717  7794.193
        115 "00641" 2.0793223  7798.517
        141 "00641" 4.3896804  7817.786
        206 "00646"  5.861665 34.359116
        152 "00646"  2.344666  39.85657
        114 "00646"  71.39507  5137.113
        134 "00646"  3.048066  5146.404
        162 "00646" 14.771395  5364.598
        119 "00646" 2.5791326   5371.25
        128 "00647"       100     10000
        152 "00650" 22.392574  501.4274
        141 "00650"  75.86566  6257.026
        134 "00650"   .458907  6257.237
        135 "00650" 1.2828536  6258.882
        141 "00652" 10.162601 103.27847
        135 "00652" 18.495935  445.3781
        152 "00652"  67.88618  5053.911
        125 "00652" 3.4552846   5065.85
        117 "00653"  1.978022  3.912571
        128 "00653"  98.02198  9612.221
        124 "00656"  5.839416 34.098778
        117 "00656"  68.90511  4782.013
        128 "00656" 25.255474  5419.853
        152 "00659"  .4876107  .2377642
        135 "00659"  79.79899  6368.116
        125 "00659" 17.126081  6661.419
        159 "00659" 2.1295652  6665.954
        141 "00659"   .457757  6666.164
        128 "00660"       100     10000
        end

        Comment


        • #5
          sum() gives a cumulative or running sum, so it’s the last value you want from each zip code. Or use egen‘s total() function.

          Comment


          • #6
            Thank you, Dr. Cox.
            This produced what I needed:
            bysort num_zipcode: egen hhi=total(market_share^2)

            Comment


            • #7
              Using percents means that the HHI runs on a scale from 0 (almost) to 10000. I find it more useful to convert to a numbers equivalent, the equivalent number of companies with equal shares, varying from 1 (monopoly) upwards. Each zip code should be plotted just one.


              Code:
              egen HHI = total(market_share^2), by(zipcode)
              gen numbers_equivalent = 10000/HHI 
              egen tag = tag(zipcode)
              
              quantile numbers_equivalent if tag, scheme(s1color) ms(S) mc(blue) rlopts(lc(none)) yla(, ang(h))

              Click image for larger version

Name:	hhi.png
Views:	1
Size:	15.3 KB
ID:	1646818

              Comment

              Working...
              X