title: Event Analysis around Earnings Announcement Dates with multiple firms and multiple dates
body: <p>I am trying to compute Cumulative Abnormal Returns per firm around the EPS announcement dates by using the <code>EvReturn</code> function from the <code>erer</code>package. I have a dataframe (<strong>df</strong>) with column Date (time-series), 5 columns with daily firms returns, and last column with the market index returns. The second dataframe (<strong>Dates_clean</strong>), consists of 2 columns, one referring to the firms and the second with the announcement dates. This dataframe has been tidied and cleaned from NAs and it is possible that a firm is not present due to missing observations regarding EPS dates.
  <strong>df</strong> looks as follow (subset only for the last 2 years, daily observations of returns):</p>
  <pre><code>df &lt;-- structure(list(Date = c(&quot;2021-12-31&quot;, &quot;2022-01-03&quot;, &quot;2022-01-04&quot;, 
  &quot;2022-01-05&quot;, &quot;2022-01-06&quot;, &quot;2022-01-07&quot;, &quot;2022-01-10&quot;, &quot;2022-01-11&quot;, 
  &quot;2022-01-12&quot;, &quot;2022-01-13&quot;, &quot;2022-01-14&quot;, &quot;2022-01-17&quot;, &quot;2022-01-18&quot;, 
  &quot;2022-01-19&quot;, &quot;2022-01-20&quot;, &quot;2022-01-21&quot;, &quot;2022-01-24&quot;, &quot;2022-01-25&quot;, 
  &quot;2022-01-26&quot;, &quot;2022-01-27&quot;, &quot;2022-01-28&quot;, &quot;2022-01-31&quot;, &quot;2022-02-01&quot;, 
  &quot;2022-02-02&quot;, &quot;2022-02-03&quot;, &quot;2022-02-04&quot;, &quot;2022-02-07&quot;, &quot;2022-02-08&quot;, 
  &quot;2022-02-09&quot;, &quot;2022-02-10&quot;, &quot;2022-02-11&quot;, &quot;2022-02-14&quot;, &quot;2022-02-15&quot;, 
  &quot;2022-02-16&quot;, &quot;2022-02-17&quot;, &quot;2022-02-18&quot;, &quot;2022-02-21&quot;, &quot;2022-02-22&quot;, 
  &quot;2022-02-23&quot;, &quot;2022-02-24&quot;, &quot;2022-02-25&quot;, &quot;2022-02-28&quot;, &quot;2022-03-01&quot;, 
  &quot;2022-03-02&quot;, &quot;2022-03-03&quot;, &quot;2022-03-04&quot;, &quot;2022-03-07&quot;, &quot;2022-03-08&quot;, 
  &quot;2022-03-09&quot;, &quot;2022-03-10&quot;, &quot;2022-03-11&quot;, &quot;2022-03-14&quot;, &quot;2022-03-15&quot;, 
  &quot;2022-03-16&quot;, &quot;2022-03-17&quot;, &quot;2022-03-18&quot;, &quot;2022-03-21&quot;, &quot;2022-03-22&quot;, 
  &quot;2022-03-23&quot;, &quot;2022-03-24&quot;, &quot;2022-03-25&quot;, &quot;2022-03-28&quot;, &quot;2022-03-29&quot;, 
  &quot;2022-03-30&quot;, &quot;2022-03-31&quot;, &quot;2022-04-01&quot;, &quot;2022-04-04&quot;, &quot;2022-04-05&quot;, 
  &quot;2022-04-06&quot;, &quot;2022-04-07&quot;, &quot;2022-04-08&quot;, &quot;2022-04-11&quot;, &quot;2022-04-12&quot;, 
  &quot;2022-04-13&quot;, &quot;2022-04-14&quot;, &quot;2022-04-15&quot;, &quot;2022-04-18&quot;, &quot;2022-04-19&quot;, 
  &quot;2022-04-20&quot;, &quot;2022-04-21&quot;, &quot;2022-04-22&quot;, &quot;2022-04-25&quot;, &quot;2022-04-26&quot;, 
  &quot;2022-04-27&quot;, &quot;2022-04-28&quot;, &quot;2022-04-29&quot;), NESN = c(NA, 0.0128217636632681, 
  0.0055390098819148, -0.0303446403908639, -0.00353202700477517, 
  -0.0148639604729367, -0.0242468464841654, 0.000833755941585634, 
  0.000566825263230264, -0.00107292453477992, -0.00413304805849857, 
  0.00944796286389749, 0.00606019163539706, -0.0178671560381302, 
  0.0102682549157, 0.00238042231089342, -0.0264129023440169, -0.00359737479380895, 
  -0.00057237456191328, 0.00371815995136426, -0.00208920373247656, 
  0.00360658333406638, 0.00460158995889248, 0.0124240943672786, 
  -0.0192088934850052, -0.0116772543954452, 0.00161803666364402, 
  -0.00947063835830442, 0.00910418738855001, -0.0111621216023017, 
  0.0149520456912964, -0.00898947983118181, -0.000580331235212728, 
  -0.00085760228693943, 0.00337970744966198, 0.00873269055978332, 
  0.0104415116340701, -0.00548153587914391, 0.00615346747892431, 
  -0.0248914439483823, 0.0173285069170668, 0.0237445174472881, 
  0.0114592474061839, -0.00044228969975324, -0.0129341888051192, 
  -0.0039655856135451, -0.0259827935397877, -0.0295994170754248, 
  0.0307311936266654, -0.013299455406402, -0.0056093783764315, 
  0.0110647313950434, 0.00334040819250792, 0.00425756006997746, 
  0.0172069005359381, 0.0251378343192163, -0.0021649080340248, 
  0.00189626896268957, -0.0135983085238801, 0.0114262007450368, 
  -0.00381128173575684, 0.0058674672957324, -0.00307865494333059, 
  0.00175366558880397, 0.00248499184478623, 0.00721501950695935, 
  0.0140475807883897, 0.0150789811679537, -0.0124887026538493, 
  0.00613195773358854, 0.0132145840052262, -0.0015996735360132, 
  -0.0066051386016398, 0.00478929567729036, 0.000712513206063692, 
  0, -0.00234061707177347, -0.0254790654941593, -0.002887253994175, 
  0.0031573171246464, 0.0188337863652812, 0.0128193479643504, -0.0131137915005016, 
  0.0142879572931387, 0.00363369724621165, -0.00110402156089173
  ), MC = c(NA, 0.00550261575073563, 0.0177834448996657, 0.0188176125853796, 
  -0.0407649022737596, -0.0155420098162522, -0.0183010694192803, 
  0.0103886467592562, -0.00183070448319778, -0.0263867607751148, 
  -0.021159281495444, 0.0162863512416866, -0.0195218616791354, 
  0.036701342749085, 0.00888605545163479, -0.00951769122788382, 
  -0.049340634153576, 0.00633645237423841, 0.0248878672659074, 
  0.0152138699844748, 0.0322766524097042, 0.00865438181820477, 
  0.0132850798110877, -0.00396012072659391, -0.0241332685589187, 
  -0.00786778247404551, 0.0141615838200913, -0.0139641131076824, 
  0.014870269120445, -0.0145131154740279, -0.0300199660152931, 
  -0.0218975214448938, 0.0358204424148594, -0.00922132830585842, 
  -0.00509031265552273, 0.00321590363749413, -0.0205452396116511, 
  -0.00446266058653078, -0.00508069260599331, -0.0449083741501392, 
  0.0482780235448934, -0.0100514536376457, -0.0516743602589363, 
  0.0194952092513918, -0.0322887147335422, -0.0641394765595972, 
  -0.0173068505872533, -0.0311734655958205, 0.0954377559421478, 
  -0.0243947811500892, 0.0119067888938236, 0.00638796543754672, 
  -0.0145319835423444, 0.065932734214486, 0.00143122890265102, 
  0.0152422943022248, -0.0096967499833438, 0.0168987761680872, 
  -0.0304396645441839, 0.000640877885772717, 0.00208067872578832, 
  0.0154956918516587, 0.0567879413578825, -0.0168206261325913, 
  -0.0168057506728613, 0.000308592594485901, 0.0220126129867861, 
  -0.00451860424097195, -0.0373729875542405, -0.0191766740018862, 
  0.0123403885706372, -0.0186802220420382, 0.0177444777777833, 
  0.005072438614252, 0.00930500067891504, 0, -3.12499902288543e-07, 
  -0.00921874999999994, 0.0129321873521526, 0.0172808575677141, 
  -0.0211199942209961, -0.0375232958098812, -0.0134827788364557, 
  0.0153135163323701, 0.000972753811222749, 0.00372650801247842
  ), ASML = c(NA, -0.00707457495736874, -0.0290725339785473, -0.0152647901460136, 
  -0.0184823371590401, 0.00971814435287954, -0.0640693722781605, 
  0.00755262856381633, 0.0307819825808584, 0.0255294675755942, 
  -0.0310802702293709, 0.0217999099657287, -0.0225541062341073, 
  -0.0236980117549149, 0.0220375314655912, -0.0167179739743669, 
  -0.070396438711375, -0.0162393217912211, 0.0253696004759689, 
  -0.0127093712930013, -0.0283213085062449, 0.0496373256889857, 
  0.0104341989959946, -0.00316405782212825, -0.0412701616473979, 
  -0.0167302195887068, 0.014887800465154, -0.0106529882383843, 
  0.0393645189761693, -0.00798216711956512, -0.024996058038682, 
  -0.017207904689711, 0.0235835268894051, 0.00174602988969963, 
  0.00749259452866369, -0.0134901418194397, -0.0343618513323983, 
  0.0248730936819173, -0.000354295774261049, -0.0108096737888227, 
  0.0553563040643841, 0.0166350336725456, -0.0362331061055623, 
  0.010395360497353, -0.0169754801097395, -0.069247700897907, 0.0131186232688818, 
  -0.0436560986000191, 0.077563666368923, -0.0210021464720349, 
  -0.00476696090336659, -0.0152907148120854, 0.011037414017806, 
  0.0712443030593835, 0.0100189998239766, 0.0430985046864196, 0.00459075408780252, 
  0.0236664062345713, -0.0212058320781517, 0.00293240036892017, 
  0.00730826701315568, 0.00403160465895103, 0.0165410283377181, 
  -0.0170617639615278, -0.0196080007058823, -0.00540967213114751, 
  0.0176357313934843, -0.0294781484344746, -0.0457273107021545, 
  -0.00769569645056023, 0.00334966691029259, -0.029861744320177, 
  0.0146653992395438, 0.010171668543006, -0.0130715444394179, 0, 
  -1.7898690185536e-07, 0.00519062108466084, 0.0530628561253561, 
  -0.0125130178368247, -0.0219178119722282, -0.0411412887152115, 
  -0.0334124520723025, -0.00132262939176431, 0.0378286505877248, 
  -0.00127556088046676), ROG = c(NA, -0.0016563124362825, -0.0167576047110743, 
  0.00558547220350492, -0.00931186868686873, 0.00929598170989054, 
  -0.0189468728798304, 0.0102378674073382, -0.0211679240011176, 
  -0.0090002397780341, 0.00835899311866473, 0.00677858618059668, 
  -0.004236109928897, 0.00246186811339411, -3.6951028517751e-05, 
  -0.0085303180179872, -0.0453608483871986, 0.00297013943738533, 
  0.00575500793484429, 0.0165975968466054, 0.00233697546175771, 
  -0.000929104641140599, 0.0127388162493018, -0.00699098766109441, 
  -0.034148341582287, -0.0182875241992058, 0.0008188551362458, 
  0.0038028755990831, 0.0290255912422577, -0.00518866385230854, 
  -0.014558705998831, -0.0111877742472386, 0.0114612566678807, 
  0.00773075782606858, -0.00964711322222001, -0.00537533349502783, 
  -0.00277687179752917, 0.0100685911308367, 0.00239370555303364, 
  -0.00492692631648861, 0.0156943530061375, 0.0141076879880042, 
  0.0095079601184076, -0.00810543484286608, -0.0153314409260049, 
  -0.00265576875393958, 0.011543968321482, 0.00650858137799504, 
  0.0172871323248192, -0.013768790740987, 0.00885575961597662, 
  0.0135187375923218, -5.44893487662845e-05, -0.00846638540982525, 
  0.00148964049045319, 0.0260458184590857, 0.0049176082464939, 
  -0.000655460348850556, -0.000953002940294323, 0.0201022930361616, 
  0.00785770864045432, -0.00585620372821327, -0.0105159715950733, 
  -0.00101256130850647, -0.00614261872165789, 0.0145685186996185, 
  0.0366446438948085, 0.00785569119190255, 0.0111315542528179, 
  0.0105840795630807, 0.0110330061523778, 0.00756508782135668, 
  -0.0247558224043232, 0.000999685813030116, -0.00142410234860157, 
  0, -0.00234052114911543, -0.0406737559105963, -0.0119804035990065, 
  -0.0253254619925773, 0.00693062609568162, -0.00655543146327209, 
  -0.0173983359583453, 0.0239373293877456, -0.00889126611629498, 
  -2.8255212379813e-06), DJSTOXX = c(NA, 0.00448956330284256, 0.00822265035062086, 
  0.000665968984872922, -0.0125074340644002, -0.00391672453668146, 
  -0.014833902655213, 0.00842939391029529, 0.00646896140565878, 
  -0.000302344092258267, -0.0100667827031564, 0.00696648315220894, 
  -0.00975618817245349, 0.00231978423713897, 0.00508630710398661, 
  -0.0184133486433087, -0.0381245455216094, 0.00708217470094685, 
  0.0167954411441527, 0.00646040726886765, -0.0101525109126204, 
  0.00715709523318564, 0.0127472893082297, 0.0045192172025077, 
  -0.0175615871465199, -0.0138360753686276, 0.0067878981966738, 
  0.000120356858084092, 0.0171767249252694, -0.00207254104941135, 
  -0.00589392210453665, -0.0183275230158848, 0.0143092365731592, 
  0.000447004322467581, -0.0068709568459443, -0.00805937763694919, 
  -0.0130249474835507, 0.000692602999960323, -0.00277069175010591, 
  -0.0328295068963999, 0.0331852560597776, -0.000926074963563228, 
  -0.0237052175314, 0.00896542681851686, -0.020101628384252, -0.0356274007682458, 
  -0.0110105316066746, -0.00508229969266472, 0.0468249263880254, 
  -0.0168766270684341, 0.00950095407560014, 0.0120160585194342, 
  -0.00282797911787214, 0.0306352270637984, 0.00455346192440631, 
  0.0091122594851849, 0.000435550608561153, 0.00846535252146574, 
  -0.0100600682445028, -0.00211439307007666, 0.00104840080252311, 
  0.00137141546833175, 0.0174494900565429, -0.00411821862698636, 
  -0.00940915708728995, 0.00543807309261601, 0.00839116898191072, 
  0.00191698129536877, -0.015334581522056, -0.0020812772770139, 
  0.0130697264521857, -0.00588544107183153, -0.0035024167766855, 
  0.000289061644585642, 0.00664430735011456, 0, 0, -0.00769436536709167, 
  0.00837864552170919, 0.00318842343654246, -0.0178911495356058, 
  -0.0180825084765205, -0.00902690097368308, 0.00728639570524336, 
  0.00620287637010186, 0.00743961741666777)), class = &quot;data.frame&quot;, row.names = c(NA, 
  -86L))
  </code></pre>
  <p>Whereas, <strong>Dates_clean</strong> is:</p>
  <pre><code>Dates_clean &lt;-- structure(list(stock = c(&quot;NESN&quot;, &quot;NESN&quot;, &quot;MC&quot;, &quot;ASML&quot;, &quot;ASML&quot;, 
  &quot;ROG&quot;, &quot;ROG&quot;), EPS = structure(c(19103, 19040, 19019, 19102, 
  19011, 19107, 19026), class = &quot;Date&quot;)), row.names = c(&quot;33&quot;, &quot;130&quot;, 
  &quot;260&quot;, &quot;293&quot;, &quot;390&quot;, &quot;423&quot;, &quot;520&quot;), class = &quot;data.frame&quot;, na.action = structure(c(`NA` = 1L, 
  NA.1 = 2L, NA.2 = 3L, NA.3 = 4L, NA.4 = 5L, NA.5 = 6L, NA.6 = 7L, 
  NA.7 = 8L, NA.8 = 9L, NA.9 = 10L, NA.10 = 11L, NA.11 = 12L, NA.12 = 13L, 
  NA.13 = 14L, NA.14 = 15L, NA.15 = 16L, NA.16 = 17L, NA.17 = 18L, 
  NA.18 = 19L, NA.19 = 20L, NA.20 = 21L, NA.21 = 22L, NA.22 = 23L, 
  NA.23 = 24L, NA.24 = 25L, NA.25 = 27L, NA.26 = 28L, NA.27 = 29L, 
  NA.28 = 30L, NA.29 = 31L, NA.30 = 32L, NA.31 = 33L, NA.32 = 34L, 
  NA.33 = 35L, NA.34 = 36L, NA.35 = 37L, NA.36 = 38L, NA.37 = 39L, 
  NA.38 = 40L, NA.39 = 41L, NA.40 = 42L, NA.41 = 43L, NA.42 = 44L, 
  NA.43 = 45L, NA.44 = 46L, NA.45 = 47L, NA.46 = 48L, NA.47 = 49L, 
  NA.48 = 50L, NA.49 = 51L, NA.50 = 52L, NA.51 = 53L, NA.52 = 54L, 
  NA.53 = 55L, NA.54 = 57L, NA.55 = 58L, NA.56 = 59L, NA.57 = 60L, 
  NA.58 = 61L, NA.59 = 62L, NA.60 = 63L, NA.61 = 64L, NA.62 = 65L, 
  NA.63 = 66L, NA.64 = 67L, NA.65 = 68L, NA.66 = 69L, NA.67 = 70L, 
  NA.68 = 71L, NA.69 = 72L, NA.70 = 73L, NA.71 = 74L, NA.72 = 75L, 
  NA.73 = 76L, NA.74 = 77L, NA.75 = 78L, NA.76 = 79L, NA.77 = 80L, 
  NA.78 = 81L, NA.79 = 82L, NA.80 = 83L, NA.81 = 84L, NA.82 = 85L, 
  NA.83 = 86L, NA.84 = 87L, NA.85 = 88L, NA.86 = 89L, NA.87 = 90L, 
  NA.88 = 91L, NA.89 = 92L, NA.90 = 93L, NA.91 = 94L, NA.92 = 95L, 
  NA.93 = 96L, NA.94 = 97L, NA.95 = 98L, NA.96 = 99L, NA.97 = 100L, 
  NA.98 = 101L, NA.99 = 102L, NA.100 = 103L, NA.101 = 104L, NA.102 = 106L, 
  NA.103 = 107L, NA.104 = 108L, NA.105 = 109L, NA.106 = 110L, NA.107 = 111L, 
  NA.108 = 112L, NA.109 = 113L, NA.110 = 114L, NA.111 = 115L, NA.112 = 116L, 
  NA.113 = 117L, NA.114 = 118L, NA.115 = 119L, NA.116 = 120L, NA.117 = 121L, 
  NA.118 = 122L, NA.119 = 124L, NA.120 = 125L, NA.121 = 126L, NA.122 = 127L, 
  NA.123 = 128L, NA.124 = 129L, NA.125 = 130L, NA.126 = 131L, NA.127 = 132L, 
  NA.128 = 133L, NA.129 = 134L, NA.130 = 135L, NA.131 = 136L, NA.132 = 137L, 
  NA.133 = 138L, NA.134 = 139L, NA.135 = 140L, NA.136 = 141L, NA.137 = 142L, 
  NA.138 = 143L, NA.139 = 144L, NA.140 = 145L, NA.141 = 146L, NA.142 = 147L, 
  NA.143 = 148L, NA.144 = 149L, NA.145 = 150L, NA.146 = 151L, NA.147 = 152L, 
  NA.148 = 153L, NA.149 = 155L, NA.150 = 156L, NA.151 = 157L, NA.152 = 158L, 
  NA.153 = 159L, NA.154 = 160L, NA.155 = 161L, NA.156 = 162L, NA.157 = 163L, 
  NA.158 = 164L, NA.159 = 165L, NA.160 = 166L, NA.161 = 167L, NA.162 = 168L, 
  NA.163 = 169L, NA.164 = 170L, NA.165 = 171L, NA.166 = 172L, NA.167 = 173L, 
  NA.168 = 174L, NA.169 = 175L, NA.170 = 177L, NA.171 = 178L, NA.172 = 179L, 
  NA.173 = 180L, NA.174 = 181L, NA.175 = 182L, NA.176 = 183L, NA.177 = 184L, 
  NA.178 = 185L, NA.179 = 186L, NA.180 = 187L, NA.181 = 188L, NA.182 = 189L, 
  NA.183 = 190L, NA.184 = 191L, NA.185 = 192L, NA.186 = 193L, NA.187 = 194L, 
  NA.188 = 195L, NA.189 = 196L, NA.190 = 197L, NA.191 = 198L, NA.192 = 199L, 
  NA.193 = 200L, NA.194 = 201L, NA.195 = 202L, NA.196 = 203L, NA.197 = 204L, 
  NA.198 = 205L), class = &quot;omit&quot;))
  </code></pre>
  <p>Those are subsets of my original dataframes, encompassing more than 20 years of daily observations and 250 firms.
  My goal is to compute automatically cumulative abnormal returns for each firm around each earnings announcement date. I was able to compute the simple 1 firm or multiple firms with 1 event date in common for all. I am struggling in telling R how to match each date and firm with the dataframe containing returns and then compute the cumulative abnormal returns.
  Until now I have tried this code:</p>
  <pre><code>hh2 &lt;- list()
  for(i in Dates_clean[2]){
  firms &lt;- colnames(df)[2:6]
  hh2[[i]] &lt;- evReturn(y = df, firm = firms, event.date = i, y.date = &quot;Date&quot;, index = &quot;DJSTOXX&quot;, event.win = 3, est.win = 100, digits = 4)}
  Error in xj[i] : only 0's may be mixed with negative subscripts
  </code></pre>
  <p>Any help is highly appreciated.</p>