I want to use a for loop to compute cumulative abnormal returns in R and have the dates in column 1, company names (comn) in 2, and stock prices (prccd) in 3. However, to compute abnormal returns I first need to compute the returns and thus need the company names with subsequent stock prices to be able to do this. Now my df looks like this;
| Date | conm | prccd | 
|---|---|---|
| 2016-11-02 | X | 1 | 
| 2016-11-02 | Y | 2 | 
| 2016-11-02 | Z | 3 | 
And thus need the data frame to look like:
| Date | X | Y | Z | 
|---|---|---|---|
| 2016-11-02 | 1 | 2 | 3 | 
| 2016-11-03 | 2 | 3 | 4 | 
| 2016-11-04 | 3 | 4 | 5 |