Hi,

I am new to the forum and to stata as well. I know this topic has been covered multiple times but I am not getting the desired output. I am looking to create the HHI (Herfindahl-Hirschman Index) for US firms per year. The dataex below shows part of the dataset intend to use, based on the forum search the data below should be sufficient to create the HHI (please inform me if I am incorrect in the matter)

The id variables for the firms are GVKEY, lpermno and cusip_6 (A shortened version of CUSIP). sale is the net sales of the firm, mkvalt is the market value of the firm, sic2d is the 2 digit SIC code.

I have tried the following: Using HHI and HHI5 program I tried:
Code:
hhi sale, by (year sic2d)
and got the error "Negative values in varlist" . I tried dropping missing variables, thinking that might help, but still got the same result. Ref: https://www.statalist.org/forums/for...rfindahl-index

I then tried what Nick Cox stated in the same post linked above and tested this:
Code:
entropyetc sale, by(sic2d year)
and got the error of too many values.

I understand this is not a unique case and is answered multiple times, answer is probably simple but I can't seem to figure it out. I do apologies for the repeat of this topic but I I'd appreciate the help! Thanks!

Code:
input str6(gvkey cusip_6) double(lpermno year sale mkvalt) str2 sic2d
"178698" "000307" 14945 2014  132.968   660.8841 "80"
"178698" "000307" 14945 2015  212.261   434.8348 "80"
"178698" "000307" 14945 2016   279.77   171.3998 "80"
"178698" "000307" 14945 2017  317.641    214.848 "80"
"021542" "000360" 76868 2009  245.282   335.5204 "35"
"021542" "000360" 76868 2010  244.552   465.6343 "35"
"021542" "000360" 76868 2011   266.22   504.4228 "35"
"021542" "000360" 76868 2012  303.114   511.6907 "35"
"021542" "000360" 76868 2013   321.14  1172.9165 "35"
"021542" "000360" 76868 2014  356.322  1210.0004 "35"
"021542" "000360" 76868 2015  358.632  1230.9386 "35"
"021542" "000360" 76868 2016  383.977  1740.1156 "35"
"021542" "000360" 76868 2017  405.232  1923.9241 "35"
"001004" "000361" 54594 2009 1352.151   777.8348 "50"
"001004" "000361" 54594 2010 1775.782  1049.8206 "50"
"001004" "000361" 54594 2011 2074.498   485.2897 "50"
"001004" "000361" 54594 2012   2167.1   790.0029 "50"
"001004" "000361" 54594 2013     2035    961.308 "50"
"001004" "000361" 54594 2014   1594.3  1046.3954 "50"
"001004" "000361" 54594 2015   1662.6   842.5112 "50"
"001004" "000361" 54594 2016   1767.6  1200.3288 "50"
"210418" "000375" 88953 2009    31795          . "36"
"210418" "000375" 88953 2010    31589          . "36"
"210418" "000375" 88953 2011    37990          . "36"
"210418" "000375" 88953 2012    39336          . "36"
"210418" "000375" 88953 2013    41848          . "36"
"210418" "000375" 88953 2014    39830          . "36"
"210418" "000375" 88953 2015    35481          . "36"
"210418" "000375" 88953 2016    33828          . "36"
"210418" "000375" 88953 2017    34312          . "36"
"164506" "00081T" 90825 2009   1272.5   397.2842 "27"
"164506" "00081T" 90825 2010   1330.5    467.944 "27"
"164506" "00081T" 90825 2011   1318.4   535.3434 "27"
"164506" "00081T" 90825 2012   1758.5   830.4696 "27"
"164506" "00081T" 90825 2013   1765.1   763.8221 "27"
"164506" "00081T" 90825 2014   1689.2  1008.3181 "27"
"164506" "00081T" 90825 2015   1510.4   753.2132 "27"
"164506" "00081T" 90825 2016   1557.1  1408.1864 "27"
"164506" "00081T" 90825 2017   1948.8  1301.5448 "27"
"017173" "000868" 12480 2010   56.734    93.0103 "60"
"017173" "000868" 12480 2011   53.569    82.2332 "60"
"017173" "000868" 12480 2012   52.243    96.5137 "60"
"017173" "000868" 12480 2013   49.304   108.1975 "60"
"017173" "000868" 12480 2014    49.43    130.848 "60"
"017173" "000868" 12480 2015    51.87    128.652 "60"
"017173" "000868" 12480 2016   53.259      189.5 "60"
"017173" "000868" 12480 2017   65.934   207.5592 "60"
"065569" "00086T" 85452 2009  468.889    73.0649 "59"
"065569" "00086T" 85452 2010  448.058    63.6185 "59"
"001013" "000886" 50906 2009    996.7    805.644 "36"
"001013" "000886" 50906 2010   1156.6   1231.524 "36"
"061523" "00088U" 82544 2009   28.161     41.601 "73"
"017653" "000899" 15056 2014    5.916   103.7916 "28"
"017653" "000899" 15056 2015    7.177    86.4539 "28"
"017653" "000899" 15056 2016   10.661    65.9814 "28"
"017653" "000899" 15056 2017   15.761   145.4676 "28"
"001410" "000957" 47730 2009 3481.823   970.7006 "73"
"001410" "000957" 47730 2010 3495.747  1186.9193 "73"
"001410" "000957" 47730 2011 4246.842  1078.3933 "73"
"001410" "000957" 47730 2012 4300.265   1033.486 "73"
"001410" "000957" 47730 2013 4809.281  1526.1998 "73"
"001410" "000957" 47730 2014   5032.8  1539.2992 "73"
"001410" "000957" 47730 2015   4897.8  1593.4104 "73"
"001410" "000957" 47730 2016   5144.7  2172.8089 "73"
"001410" "000957" 47730 2017   5453.6  2749.1609 "73"
"014438" "00101J" 13567 2013     3309  8497.1675 "73"
"014438" "00101J" 13567 2014     3408  6173.9051 "73"
"014438" "00101J" 13567 2015     3574   4958.915 "73"
"011903" "001031" 10025 2009  744.819   238.9978 "30"
"011903" "001031" 10025 2010   800.57   149.7049 "30"
"011903" "001031" 10025 2011  974.792   148.3947 "30"
"011903" "001031" 10025 2012 1152.535   353.5968 "30"
"011903" "001031" 10025 2013 1143.852   332.8114 "30"
"011903" "001031" 10025 2014  1192.99   233.6752 "30"
"011903" "001031" 10025 2015 1141.391     408.24 "30"
"011903" "001031" 10025 2016  1095.83   560.2387 "30"
"001449" "001055" 57904 2009    18237          . "63"
"001449" "001055" 57904 2010    20732          . "63"
"001449" "001055" 57904 2011    22171 20172.5706 "63"
"001449" "001055" 57904 2012    25364          . "63"
"001449" "001055" 57904 2013    23939          . "63"
"001449" "001055" 57904 2014    22728          . "63"
"001449" "001055" 57904 2015    20904  25420.362 "63"
"001449" "001055" 57904 2016    22374          . "63"
"001449" "001055" 57904 2017    21700          . "63"
"025180" "001084" 77520 2009   6630.4  2989.9624 "35"
"025180" "001084" 77520 2010   6896.6   4718.675 "35"
"025180" "001084" 77520 2011   8773.2  4176.4692 "35"
"025180" "001084" 77520 2012   9962.2  4755.6019 "35"
"025180" "001084" 77520 2013  10786.9  5762.8568 "35"
"025180" "001084" 77520 2014   9723.7  4029.3992 "35"
"025180" "001084" 77520 2015   7467.3  3804.3629 "35"
"025180" "001084" 77520 2016   7410.5  4597.8449 "35"
"025180" "001084" 77520 2017   8306.5  5682.5422 "35"
"032638" "00108J" 17045 2017   36.506    80.5613 "35"
"011361" "00108M" 63829 2009   52.526    23.6557 "50"
"011361" "00108M" 63829 2010   45.704    24.3934 "50"
"011361" "00108M" 63829 2011   42.894    23.4219 "50"
"011361" "00108M" 63829 2012   51.117    20.7673 "50"
"011361" "00108M" 63829 2013   57.916    20.8248 "50"
end