Hello all,
I am having some difficulties with creating peer group returns using the data shown below. As you can see, I have managed to create the variable Sreturnmean using
Code:
 egen Sreturnmean = mean(Ret), by(FirmSizeQuartiles YEAR)
However, I need for the value of Sreturnmean to NOT include that of the observation in question. What I mean is that it should contain the mean FirmRet of all the observations in the same YEAR and FirmSizeQuartile excluding its own return from the calculation. I received the recommendation to use the -egenmore- function - sumoth(exp)-, but I could not figure out how to use it with my data. I have already used this method and was wondering if I could simply alter this to achieve my goal. Thank you for the help!
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input double YEAR long GVKEY double TotalComp float FirmRet double FirmSize byte FirmSizeQuartiles float Sreturnmean
2014 1 1260.3956098658957    .04133067 1582.3278103151958 3   .09756514
2015 1 1540.5627306134697    .03051127 1638.2539436121074 3   -.0420502
2016 1  4309.262573660955     .3070665 1706.8252653220186 3   .21314347
2017 1  3918.166503288153    .18616717 1654.4938088568747 3   .18194717
2018 1 3935.9937059066892  -.022628257  1907.230939616466 3  -.09177586
2019 1 3127.5019471963337    .22319357 1901.6958854228992 3    .2392718
2013 2   17399.8258601099            0 26316.784281371332 4   .30474555
2014 2 12030.286205096598     .8415493  41708.07247936184 4   .12872379
2015 2 11087.274656952859   -.17650238  39800.80724706021 4 -.032631863
2016 2   133.980311115709     .1707375  38243.91992660846 4   .17469014
2017 2 16903.261118333536    .13536066  39382.65537129413 4    .1605121
2018 2 11000.474483974254    -.3649902  40832.65468024232 4   -.0974269
2019 2 10390.626166311284   -.02171545  41096.60663750718 4   .25308645
2000 3   8217.29353005795     .7942322 179.83329283581014 1   .27376583
2001 3 19503.575156837604   .004744023 221.85166462529557 1   .25196165
2002 3 2152.7612614426325   -.51228803 188.82085520380355 1  -.16553766
2003 3   772.629690590804     .6655167  267.2103508479418 1    .5984556
2004 3   5122.14834884277    .10205846 368.25151633281286 1   .12899871
2005 3  882.1714359266732   -.03859569 399.91924812185675 1   .07834718
2006 3  864.4529406588957    .10293607 466.05895578508296 2   .17657077
2015 4  872.3742134094992    -.0940312  1186.871025246712 2 -.013554958
2016 4  991.0560937287677    .28737387  1276.857035361672 2     .277992
2017 4  1057.846285734154      .132582 1489.3021548144625 3   .18194717
2018 4 1265.1072783499262   -.02473079  1677.337999701512 3  -.09177586
2007 5  2260.280587617209   -.10725982 3385.4473688719727 3   .05917528
2008 5 1679.3367280620314    -.1865099  3232.200968539843 3   -.3322243
2009 5 3739.4569397080554     .2268892 3084.4546552809597 3    .4875262
2010 5  4432.600545475986     .1726896  3011.025861291741 3    .2763271
2011 5  6015.086454762044     .1857807  2910.931537160236 3    .0490157
2012 5  8950.741431832344     .0909292  2919.546765855608 3    .1887559
2013 5 6216.5762647024085    .07965531   3014.64644697854 3    .3073079
2014 5  6394.526608230907    .27426022  3026.952001036648 3   .09756514
2015 5  6748.699685273985 -.0041726558 3011.2129976295682 3   -.0420502
2016 5  7820.517151085741    .20234816 2961.0830071950536 3   .21314347
2017 5   6786.42792726156    .10843728 2964.5436911683055 3   .18194717
2018 5  8131.869393503942    .03622571  3021.282274405443 3  -.09177586
2019 5  7681.599917119302    .07598463 2789.0181567390878 3    .2392718
1998 6  6134.103732792758     .4358018 12279.907869353854 4    .3122305
1999 6  8225.655309270564   -.24728647 12634.752270152208 4  .037215117
2000 6  7404.304351546293     .3211931 12765.105781003525 4  -.02294118
2001 6 14859.474566123106    .17023645 14908.416643546885 4  .006314414
2002 6  22008.66701661294   -.23682033 15844.748765446993 4 -.020476514
2003 6  8664.447955363034     .1750021  17340.99461040213 4    .3484402
2004 6  9704.598389681083     .0872201 16856.941430699884 4    .2001965
2005 6 12369.687168300583   -.10712032 18548.009183619724 4    .0693005
2006 6 17264.856043490112     .2032605 18317.577641542342 4   .12242407
2007 6 22838.407814899205    .13882129 20439.523560413087 4    .0550822
2008 6  19786.24859028601  -.011233186  23272.68586505331 4   -.3812599
2009 6 15678.988584544375    .05870697 23738.620652585018 4    .4557288
2010 6 15274.531736505147   -.05617443  26825.70442366504 4   .24132307
end