Hello,

I have a set of industries within one sector and I would like to calculate the degree of concentration of industries per country and per year. For instance, if country A had high concentration of their manufacturing sector in X or Z industries (isic). My first attempt was naturally calculating the Herfindahl index. Based on the definition, I did the following syntax

egen double totalvalueadded=sum(ValueAdded), by(country year)

bysort country year: g double squared= (ValueAdded/totalvalueadded)^2 (A proxy for market shares squared)

egen double HHI=sum(squared), by(country year)

Nevertheless, the plots that I am getting are very strange (that's why I am not showing them). Therefore, I am very sure there is something wrong in this calculation. My end goal is to verify which industries (isic) dominate in the sector per country and year and based on that explore certain industries characteristics by countries so later I can try to check patterns across regions throughout time. Thank you very much for the help!

Code:
 * Example generated by -dataex-. To install: ssc install dataex
clear
input int(country year) byte isic long(Establishments Employment) double OutputINDSTAT4 float(val_per_worker lval_per_worker region totalemployment share_val) double ValueAdded float totalval
4 1973 33 .     0 . . . 0 45486 . . 0
4 1973 27 .     0 . . . 0 45486 . . 0
4 1973 19 .     . . . . 0 45486 . . 0
4 1973 26 .  1295 . . . 0 45486 . . 0
4 1973 21 .     0 . . . 0 45486 . . 0
4 1973 28 .     0 . . . 0 45486 . . 0
4 1973 17 . 12555 . . . 0 45486 . . 0
4 1973 35 .     . . . . 0 45486 . . 0
4 1973 25 .   360 . . . 0 45486 . . 0
4 1973 23 .     0 . . . 0 45486 . . 0
4 1973 15 .  4321 . . . 0 45486 . . 0
4 1973 24 .   259 . . . 0 45486 . . 0
4 1973 20 .  1941 . . . 0 45486 . . 0
4 1973 34 .     0 . . . 0 45486 . . 0
4 1973 16 .     0 . . . 0 45486 . . 0
4 1973 29 .     0 . . . 0 45486 . . 0
4 1973 36 .     . . . . 0 45486 . . 0
4 1973 31 .     0 . . . 0 45486 . . 0
4 1973 32 .     . . . . 0 45486 . . 0
4 1973 22 .  1287 . . . 0 45486 . . 0
4 1973 18 .   725 . . . 0 45486 . . 0
4 1974 33 .     0 . . . 0 56242 . . 0
4 1974 28 .     0 . . . 0 56242 . . 0
4 1974 34 .     0 . . . 0 56242 . . 0
4 1974 16 .     0 . . . 0 56242 . . 0
4 1974 22 .  1326 . . . 0 56242 . . 0
4 1974 15 .  4845 . . . 0 56242 . . 0
4 1974 20 .  2044 . . . 0 56242 . . 0
4 1974 23 .     0 . . . 0 56242 . . 0
4 1974 18 .   720 . . . 0 56242 . . 0
4 1974 27 .     0 . . . 0 56242 . . 0
4 1974 36 .     . . . . 0 56242 . . 0
4 1974 35 .     . . . . 0 56242 . . 0
4 1974 19 .     . . . . 0 56242 . . 0
4 1974 21 .     0 . . . 0 56242 . . 0
4 1974 32 .     . . . . 0 56242 . . 0
4 1974 25 .   427 . . . 0 56242 . . 0
4 1974 17 . 14243 . . . 0 56242 . . 0
4 1974 29 .     0 . . . 0 56242 . . 0
4 1974 24 .  3281 . . . 0 56242 . . 0
4 1974 26 .  1235 . . . 0 56242 . . 0
4 1974 31 .     0 . . . 0 56242 . . 0
4 1975 21 .     0 . . . 0 66292 . . 0
4 1975 22 .  1447 . . . 0 66292 . . 0
4 1975 31 .     0 . . . 0 66292 . . 0
4 1975 24 .  4046 . . . 0 66292 . . 0
4 1975 19 .     . . . . 0 66292 . . 0
4 1975 27 .     0 . . . 0 66292 . . 0
4 1975 36 .     . . . . 0 66292 . . 0
4 1975 25 .   507 . . . 0 66292 . . 0
4 1975 17 . 17202 . . . 0 66292 . . 0
4 1975 26 .  1646 . . . 0 66292 . . 0
4 1975 34 .     0 . . . 0 66292 . . 0
4 1975 28 .     0 . . . 0 66292 . . 0
4 1975 33 .     0 . . . 0 66292 . . 0
4 1975 32 .     . . . . 0 66292 . . 0
4 1975 16 .     0 . . . 0 66292 . . 0
4 1975 29 .     0 . . . 0 66292 . . 0
4 1975 15 .  5103 . . . 0 66292 . . 0
4 1975 18 .   874 . . . 0 66292 . . 0
4 1975 23 .     0 . . . 0 66292 . . 0
4 1975 20 .  2321 . . . 0 66292 . . 0
4 1975 35 .     . . . . 0 66292 . . 0
4 1976 36 .     . . . . 0 72158 . . 0
4 1976 16 .     0 . . . 0 72158 . . 0
4 1976 23 .     0 . . . 0 72158 . . 0
4 1976 35 .     . . . . 0 72158 . . 0
4 1976 19 .     . . . . 0 72158 . . 0
4 1976 31 .     0 . . . 0 72158 . . 0
4 1976 20 .  2317 . . . 0 72158 . . 0
4 1976 28 .     0 . . . 0 72158 . . 0
4 1976 24 .  4479 . . . 0 72158 . . 0
4 1976 17 . 20520 . . . 0 72158 . . 0
4 1976 15 .  4540 . . . 0 72158 . . 0
4 1976 18 .   840 . . . 0 72158 . . 0
4 1976 29 .     0 . . . 0 72158 . . 0
4 1976 32 .     . . . . 0 72158 . . 0
4 1976 22 .  1465 . . . 0 72158 . . 0
4 1976 34 .     0 . . . 0 72158 . . 0
4 1976 21 .     0 . . . 0 72158 . . 0
4 1976 25 .   583 . . . 0 72158 . . 0
4 1976 27 .     0 . . . 0 72158 . . 0
4 1976 33 .     0 . . . 0 72158 . . 0
4 1976 26 .  1335 . . . 0 72158 . . 0
4 1977 18 .   920 . . . 0 77018 . . 0
4 1977 16 .     0 . . . 0 77018 . . 0
4 1977 29 .     0 . . . 0 77018 . . 0
4 1977 21 .     0 . . . 0 77018 . . 0
4 1977 25 .   623 . . . 0 77018 . . 0
4 1977 20 .  2240 . . . 0 77018 . . 0
4 1977 33 .     0 . . . 0 77018 . . 0
4 1977 17 . 20540 . . . 0 77018 . . 0
4 1977 19 .     . . . . 0 77018 . . 0
4 1977 28 .     0 . . . 0 77018 . . 0
4 1977 22 .  1747 . . . 0 77018 . . 0
4 1977 35 .     . . . . 0 77018 . . 0
4 1977 27 .     0 . . . 0 77018 . . 0
4 1977 36 .     . . . . 0 77018 . . 0
4 1977 31 .     0 . . . 0 77018 . . 0
4 1977 24 .  4714 . . . 0 77018 . . 0
end