title: For Loop for Event Study using the EvReturn Function from R Package "Erer"
body: <p>forgive me if this question is trivial for some of you but I am a complete newbie to R...</p>
  
  <p>I want to use the function "evReturn()" from the R Package "erer". It is a function to calculate cumulative abnormal returns and looks like this for one firm and one market index: </p>
  
  <pre><code>hh &lt;- evReturn(y = dataset, firm = "Firm1", 
  y.date = "date", index = "Index1", est.win = 250, 
  digits = 3, event.date = 19990505, event.win = 5)
  </code></pre>
  
  <p>This works just fine if I have a matrix with 3 columns (Date, Stock returns of firm 1 and index return of index 1).</p>
  
  <p>Now the case is a bit more complicated. I have appr. 3000 firms and 3000 different indices. So in column 1, I have the dates. In columns 2-3001, I have the stock returns for all firms. In columns 3002-6001 I have the returns of the indices. </p>
  
  <p>I thought I could run the evReturn() function for all firms and all indices with a for loop like this</p>
  
  <pre><code> &gt; for(i in 2:3001) 
     {hh &lt;- evReturn(y=numt,firm=i,event.date=20140102,y.date="Date",
     index=i+3000,event.win=2,est.win=230,digits=3)}
  </code></pre>
  
  <p>But it only returns </p>
  
  <pre><code>Error in [.data.frame`(y, (loca - event.win - est.win):
  (loca - event.win -  : undefined columns selected
  </code></pre>
  
  <p>I am aware of several posts that resolve the error of "undefined columns selected" but none helps here. Has anyone an idea how I could create a for loop to let the evReturn() run through all my columns?</p>
  
  <p>Any help is appreciated!</p>
  
  <p>Cheers,
  Paul</p>