Dear all,

I am looking to calculate the Herfindahl index over the variable "industry" by group "ID" in a time-variant manner "date".

Observations per ID are sorted in time-ascending order and the HHI should be re-calculated at each date, taking into consideration all previous data for the respective ID.

I am familiar with the user-written command hhi, but unsure how implement the time-varying component. For example,
Code:
hhi industry, by(ID)
would give a time-stable HHI for each ID.

I would very much appreciate your help, please also find below an example of my data. Many thanks in advance!

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int ID float(industry date)
2073 4 18774
2073 3 19488
2073 4 19792
2073 3 19831
2073 4 19920
2073 4 20104
2073 3 20627
2073 3 20690
2081 4 14851
2081 3 15239
2081 1 15795
2081 4 16279
2081 1 16972
2081 4 17784
2081 1 18613
end
format %d date