0

I have a data.frame of the following structure (panel data), with 16 levels of time(quarters) 14 levels of geo (countries) and 20 levels of citizen, each of them repeating accordingly in the dataframe.

  time     geo                          citizen      X 
2008Q1 Belgium                      Afghanistan     22
2008Q1 Belgium                          Armenia     10
2008Q1 Belgium                       Bangladesh     25
2008Q1 Belgium Democratic Republic of the Congo     55
2008Q1 Belgium      China (including Hong Kong)      5
2008Q1 Belgium                          Eritrea      8

I would like to create a new column lets say MOVSUM where it will sum variable X for each level of citizen and geo and time for the previous 4 quarters, so that I would have for each quarter, t, how many X's of each citizen in each geo were available during t-4 to t-1 quarters.

Thanks in advance

  • 1
    what have you tried? Please review this question for suggestions to make a better *reproducible* example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Chase Jun 07 '12 at 14:21
  • This question has two components. 1) Calculate a moving sum. 2) Aggregate the results for different subgroups. Both of these have *many* similar questions and answers here on SO. Where exactly do you get stuck? – Andrie Jun 07 '12 at 15:04
  • I haven't found sth that suits my problem preciesly, mainly because possibly I was looking at the problem as one component. As I am a beginner in R, I haven't done anything as I do not know how. – Alexandros BITOULAS Jun 07 '12 at 16:02

0 Answers0