I have a data frame, Returns
which looks something like this:
Date Company LstPrice r
1987-02-27 NOVO NORDISK 'B' 2.29 0.031531532
1987-03-31 NOVO NORDISK 'B' 2.33 0.017467249
1987-04-30 NOVO NORDISK 'B' 2.25 -0.034334764
1987-05-29 NOVO NORDISK 'B' 2.22 -0.013333333
1987-06-30 NOVO NORDISK 'B' 2.47 0.1126126137
1987-07-31 NOVO NORDISK 'B' 2.46 -0.004048583
1987-08-31 NOVO NORDISK 'B' 1.98 -0.195121951
1987-09-30 NOVO NORDISK 'B' 1.90 -0.040404040
1987-02-27 DANSKE BANK 24.29 -0.130637079
1987-03-31 DANSKE BANK 24.97 0.027995060
1987-04-30 DANSKE BANK 25.43 0.018422107
1987-05-29 DANSKE BANK 26.19 0.029885961
1987-06-30 DANSKE BANK 26.50 0.011836579
1987-07-31 DANSKE BANK 26.57 0.002641509
1987-08-31 DANSKE BANK 28.55 0.074520135
1987-09-30 DANSKE BANK 26.25 -0.080560420
I would want to create new data frames for different months. For example, I would want a new data frame with the observations for the first three months, a new data frame for the next three months, and so on. They would look something like this:
Data Frame, FirstThreeMonths
:
Date Company LstPrice r
1987-02-27 NOVO NORDISK 'B' 2.29 0.031531532
1987-03-31 NOVO NORDISK 'B' 2.33 0.017467249
1987-04-30 NOVO NORDISK 'B' 2.25 -0.034334764
1987-02-27 DANSKE BANK 24.29 -0.130637079
1987-03-31 DANSKE BANK 24.97 0.027995060
1987-04-30 DANSKE BANK 25.43 0.018422107
Data Frame, NextThreeMonths
:
Date Company LstPrice r
1987-05-29 NOVO NORDISK 'B' 2.22 -0.013333333
1987-06-30 NOVO NORDISK 'B' 2.47 0.1126126137
1987-07-31 NOVO NORDISK 'B' 2.46 -0.004048583
1987-05-29 DANSKE BANK 26.19 0.029885961
1987-06-30 DANSKE BANK 26.50 0.011836579
1987-07-31 DANSKE BANK 26.57 0.002641509
....and so on (I have data for approx. 2200 companies for the last 30 years, so I will have to create a lot of data frames).
I have tried several different ways, both using if
and for
loops, and the subset
command, but so far I can't get any of them to work. I also tried searching for similar questions, but couldn't find a solution that works for my exact problem. Is there an easy way to do something like this.
Every effort to help is much appreciated!