Hello,

I have the following dataset:


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double year long gid float nactors2 double EP1 float EF1 double EP2 float EF2
2016  80317 1     .15909446787289028       .329249     .15927668406477835      .3301872
2016  81037 2     .14923540560909032     .30797365       .149428310442687      .3088526
2016  81038 3      .1654487674794609      .3430555     .16562163597549784     .34403205
2016  81052 1                      0  5.960464e-08                      0  5.960464e-08
2016  81757 1     .17785356209429892     .37025005     .17800215763975302      .3713015
2016  82495 1                      0             0                      0             0
2016  84658 1                      0             0                      0             0
2016  85380 1   .0008101589379487795   .0016206935   .0008101589379487795   .0016206935
2016  85381 1       .244741527730028      .5046498     .24464178705828488      .5052092
2016  86821 3     .10218183396709968     .20657948     .10214789782470568      .2066203
2016  86822 2     .24624776118862712      .5073856     .24614028897762807     .50791466
2016  87535 1                      0             0                      0             0
2016  87536 1                      0             0                      0             0
2016  87543 1     .23132745659221854      .4734173     .23120092879512555       .473697
2016  88260 1    .002615582313610254    .005234475    .002615582313610254    .005234475
2016  88968 1      .2230424971702405      .4620102      .2230253540928402       .462782
2016  89700 1     .09642229791453083     .19445555      .1718643457042237     .41840625
2016  89701 1     .22607186008971514     .45540935      .2236408529875833      .5665542
2016  89704 1    .002615641433107996    .005234594    .002615641433107996    .005234594
2016  90424 1    .018362705333856866    .036725465    .018362705333856866    .036725465
2016  91857 5      .2017439664198939     .41057315      .2016500278216391      .4107346
2016  92575 2                      0             0                      0             0
2016  92576 1    .013623886309608313     .02731944    .013622729716882054     .02732062
2016  92577 2      .2471287256432646       .507549     .24700579334025008     .50796425
2016  92578 1     .24707616973047664      .5086244     .24696498652306786      .5091242
2016  92584 1                      0             0                      0             0
2016  92585 1      .1752788983285427      .3505577      .1752788983285427      .3505577
2016  92586 2     .19243928417563438      .3848786     .19243928417563438      .3848786
2016  93296 1    .001603235736857389     .00320772    .001603235736857389     .00320772
2016  93297 2   .0018869319070997648    .003775571   .0018869319070997648    .003775571
2016  93299 1   .0013472780395190065   .0026973665   .0013472356052584566    .002697409
2016  93302 1     .01969864491626569     .03944718    .019697839883318885     .03944802
2016  94015 1                      0             0                      0             0
2016  94027 1                      0             0                      0             0
2016  95459 1     .24714509887608926      .5080045     .24701883399083613      .5084344
2016  95471 1     .10929894261062145     .21859795     .10929894261062145     .21859795
2016  96185 1                      0             0                      0             0
2016  96214 1   .0008860708855693567   .0017728684   .0008860708855693567   .0017728684
2016  96875 1     .20917117275530472      .4475952     .20917117275530472      .4475952
2016  96930 1    .001426064835533758    .002853938    .001426064835533758    .002853938
2016  96934 1    .001328248786596653    .002658087    .001328248786596653    .002658087
2016  97654 1   .0015261118401248552     .00305436   .0015261118401248552     .00305436
2016  97656 1  5.483588388482212e-06 .000010967234  5.483588388482212e-06 .000010967234
2016  99788 1     .03192452236544341     .06384901     .03192452236544341     .06384901
2016  99813 1   .0014844337382715622    .002970942   .0014844337382715622    .002970942
2016 100498 1    .032899359124712646    .065798745    .032899359124712646    .065798745
2016 100504 1                      0             0                      0             0
2016 100506 1                      0             0                      0             0
2016 100529 1     .05442789607877785     .11182662     .05442789607877785     .11182662
2016 100530 1     .05442810242129781     .11182707     .05442810242129781     .11182707
2016 101230 1    .020886498095933348     .04177304    .020886498095933348     .04177304
2016 101253 1   .0016012039994475202   .0032047566   .0016012039994475202   .0032047566
2016 101254 1   .0014843150329273413   .0029707036   .0014843150329273413   .0029707036
2016 101947 1    .023539730056654662     .04707951    .023539730056654662     .04707951
2016 101949 1    .018495048221666366    .036990073    .018495048221666366    .036990073
2016 101970 1     .05442790250526741     .11182655     .05442790250526741     .11182655
2016 101974 1   .0014843744120174307   .0029707034   .0014843744120174307   .0029707034
2016 101978 1     .03739811228024337     .07615365     .03739811228024337     .07615365
2016 102659 1     .02900852361926809     .05801698     .02900852361926809     .05801698
2016 102660 4    .009043015677889343    .018086053    .009043015677889343    .018086053
2016 102664 1  .00023848086258126955   .0004770187  .00023848086258126955   .0004770187
2016 102665 1    .028304047300480306     .05660803    .028304047300480306     .05660803
2016 102666 1    .028770682751201093     .05754131    .028770682751201093     .05754131
2016 102667 1     .03197100223042071     .06394198     .03197100223042071     .06394198
2016 102669 2     .05117205227725208     .10234407     .05117205227725208     .10234407
2016 102696 3    .001564876744739152    .003131941    .001564876744739152    .003131941
2016 103382 1                      0             0                      0             0
2016 103383 3                      0             0                      0             0
2016 103384 1                      0             0                      0             0
2016 103385 1    .028021964186336845     .05604395    .028021964186336845     .05604395
2016 103387 3     .04349642200395465     .08699285     .04349642200395465     .08699285
2016 103388 2     .08117000991478562      .1623401     .08117000991478562      .1623401
2016 103389 1    .052885648561641574     .10577129    .052885648561641574     .10577129
2016 103390 1     .04898344282992184     .09796695     .04898344282992184     .09796695
2016 103391 1    .048983495216816664     .09796695    .048983495216816664     .09796695
2016 103392 1    .048983443761244416     .09796683    .048983443761244416     .09796683
2016 103413 1   .0014843744162043038   .0029707034   .0014843744162043038   .0029707034
2016 103416 1    .001484374404691735   .0029707036    .001484374404691735   .0029707036
2016 104091 1    .015982662851456553    .031965353    .015947537323313554    .032001354
2016 104092 1                      0             0                      0             0
2016 104102 4                      0             0                      0             0
2016 104103 5                      0             0                      0             0
2016 104107 1     .04163849935866892     .08327705     .04163849935866892     .08327705
2016 104109 2    .048930899472907186     .09786184    .048930899472907186     .09786184
2016 104111 2     .04898354993201792     .09796713     .04898354993201792     .09796713
2016 104112 2     .04898312408477068     .09796622     .04898312408477068     .09796622
2016 104137 1   .0014843150205479105   .0029707036   .0014843150205479105   .0029707036
2016 104809 1     .01244135900924448     .02488276     .01242011318583991    .024904413
2016 104821 1 5.9604641222676946e-08  5.960464e-08 5.9604641222676946e-08  5.960464e-08
2016 104832 1      .0774890654720366     .15497814      .0774890654720366     .15497814
2016 104849 1    .054427949949968024     .11182678    .054427949949968024     .11182678
2016 104856 1   .0014843744113939294    .002970763   .0014843744113939294    .002970763
2016 104858 1     .01949441962574383     .03934589     .01949441962574383     .03934589
2016 105520 1    .021412057724091937     .04300852    .021412057724091937     .04300852
2016 105540 1                      0  5.960464e-08                      0  5.960464e-08
2016 105544 1     .04811002220958471     .09622008     .04811002220958471     .09622008
2016 105549 2     .04509113263338804     .09018222     .04509113263338804     .09018222
2016 105550 1    .046692081494256854     .09338415    .046692081494256854     .09338415
2016 105551 1      .0770945749245584     .15418917      .0770945749245584     .15418917
2016 105576 1   .0014843743783803376    .002970763   .0014843743783803376    .002970763
end
The unique identifier is by Year and GID. Year goes from 2000 to 2017. Every gid has a EP1, EP2, EF1, EF2 which is fixed, that is, it does not change with time. As a example, GID = 105550 has the same value of EP1 for the entire period (2000-2017). The variable nactors2 gives the number of actors by gid and year.

I would like to make the following table:

Array

Column Freq is the number of times I have 1 actors in the sample for all the sample period and for all gid. When nactors2 is equal to 2, the same but with 2. These two columns I do with command:

Code:
tab nactors2.
However, in Column MeanEP1 I would like to have the mean of the variable EP1 of the 5689 observations in which 1 actors appears in the sample and I am not able to do it. In other words, along the period 2000-2017 there are 5689 gid in which 1 actors appears, I would like to have the average of the variable EP1 of that 5689 gid. The same with MeanEP2, ....

Please if something is not clear, let me know. Any help is more than welcome because I really do not know how to do it.