Hello Statalist, hope everyone is well

I want to calculate Gini index using following equation:
Array
where y is teny, ry is rank order, and cov(y, ry) is covariance between y and ry. y_bar is mean of y and N is the number of directors on board. i use following data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(DirectorID CompanyID tend) float teny
 855555  2   304  .8345916
1947759  6  1431   3.92862
1291925  6  1614 4.4310226
1475128  6  3865 10.610845
 327069  6  5781 15.870968
  37576  6   808 2.2182567
 341830  6  5145 14.124914
2365698  6  3655 10.034317
 341837  6  6635 18.215511
1366174  6  2519   6.91558
 543071  6   761 2.0892243
 508743  6  1916  5.260124
  33553  6  6189 16.991077
1136305  6  1584 4.3486614
1052220  6  5460 14.989705
 556521  6  2418  6.638298
 446218  6  2192  6.017845
 508736  6  4612 12.661633
 341813  6  6917 18.989704
  86917  6 11138   30.5779
 341863  6  3665  10.06177
1891128  6  1278  3.508579
  87882  6  4091 11.231297
 508723  6  2921 8.0192175
2414353  6   426 1.1695265
 333731  7  4383 12.032945
 645749  7  3583  9.836651
 886566  7  1826  5.013041
1765212  9   153  .4200412
1336543  9  1921   5.27385
2479549 11  1006 2.7618394
1140345 11   974 2.6739876
1538664 11   912  2.503775
1641444 11   365  1.002059
1455539 11   456 1.2518874
 605809 11    31 .08510638
 333598 12  3495  9.595058
1749602 12   334  .9169527
1009631 12  1299  3.566232
1009630 12  1299  3.566232
1279761 12   621  1.704873
1279758 12    48 .13177763
1124417 12  1078  2.959506
 641561 12   940  2.580645
1009636 12   515  1.413864
 371952 12   590 1.6197666
 180640 12   730  2.004118
1090208 12   731 2.0068634
 626790 12  2340  6.424159
  34066 12   365  1.002059
1009637 12  2400  6.588881
1402319 12   730  2.004118
1009641 12  1461 4.0109816
 551393 12   250  .6863418
1009642 12   822  2.256692
 552193 12  2065  5.669183
1202566 12   809  2.221002
 540291 12  2617  7.184626
1601634 12  2647  7.266987
 626804 12  1460  4.008236
 341468 12   979 2.6877146
1515539 12  1461 4.0109816
 626679 12  1058 2.9045985
1084239 12  1774  4.870281
 626665 12   730  2.004118
 451488 12   882  2.421414
1759874 12   730  2.004118
 493920 12  1319  3.621139
1009632 12  2340  6.424159
1664742 12  1430  3.925875
1043852 12   700  1.921757
  36354 12  1421  3.901167
2349795 12   792 2.1743307
1301180 12  1341 3.6815374
1009768 12  1903  5.224434
1283040 12   606 1.6636925
1009633 12  1432  3.931366
 626786 12  2340  6.424159
2270671 12   730  2.004118
1076429 12   502 1.3781743
 322452 12   699 1.9190117
1009639 12  1430  3.925875
1080985 12   365  1.002059
1251946 12   244  .6698696
1722392 12  1127  3.094029
1273767 12   650 1.7844887
 555070 12   431 1.1832533
1009624 12   273  .7494853
 374881 12  2873   7.88744
1693471 12  1581 4.3404255
1790795 12   273  .7494853
 641576 12  1179  3.236788
 310234 12  1092  2.997941
   8066 12  1852   5.08442
1513909 12   700  1.921757
1097600 12   346  .9498971
  40911 12   753 2.0672615
 626698 12  3226  8.856555
1009770 12   599  1.644475
1863745 12   731 2.0068634
end
where tend (teny) is tenure in days (years).

I already tried the following:
Code:
 ginidesc teny, by(CompanyID) m(a1) gk(a2)
too many values
r(134);
Code:
sort teny

. bys DirectorID: egen t=sum(_n*teny)

. bys DirectorID: egen s=sum(teny)

. g gini=2*t/(_N*s)-1 -1/_N

. sum gini,d

                            gini
-------------------------------------------------------------
      Percentiles      Smallest
 1%    -.9999993      -.9999993
 5%    -.9999993      -.9999993
10%    -.9999993      -.9999993       Obs           1,416,271
25%    -.9999989      -.9999993       Sum of Wgt.   1,416,271

50%     -.999998                      Mean          -.9999975
                        Largest       Std. Dev.      2.79e-06
75%     -.999997      -.9999204
90%    -.9999956      -.9999204       Variance       7.80e-12
95%    -.9999944      -.9999204       Skewness       11.03627
99%      -.99999      -.9999204       Kurtosis        205.236
drop t - gini
showing results like distribution is not by CompanyID wise. I also use the Simpson and find results below:
Code:
egen HHtag = tag(CompanyID teny)

. egen HHn = total(HHtag), by(CompanyID) 

. egen alltag = tag(teny)

. egen allN = total(alltag) 

. 
. gen Simpson = 1 - HHn * (HHn - 1) / (allN * (allN - 1)) 

. sum Simpson,d

                           Simpson
-------------------------------------------------------------
      Percentiles      Smallest
 1%     .9980935       .9964796
 5%     .9993749       .9964796
10%      .999809       .9964796       Obs           1,416,271
25%     .9999788       .9964796       Sum of Wgt.   1,416,271

50%     .9999976                      Mean           .9999008
                        Largest       Std. Dev.      .0003425
75%     .9999999              1
90%            1              1       Variance       1.17e-07
95%            1              1       Skewness      -5.436333
99%            1              1       Kurtosis       37.92618
My question is: can i construct gini index using the equation (in the picture above) ? kindly help me in this regard. thanks