I have a data set that looks like the following that I'd like to expand to a monthly panel data set.
ID | start_date | end_date | event_type |
1 | 01/01/97 | 08/01/98 | 1 |
2 | 02/01/97 | 10/01/97 | 1 |
3 | 01/01/96 | 12/01/04 | 2 |
Some cases last longer than others. I've figured out how to expand the data to a yearly configuration by pulling out the year from each date and then using:
year <- ddply(df, c("ID"), summarize, year = seq(startyear, endyear))
followed by:
month <- ddply(year, c("ID"), summarize, month = seq(1, 12))
The problem with this approach is that it doesn't assign the correct number for the month, i.e. January = 1, and so it doesn't play well with an event data set that I would like to eventually merge it with, where I would be matching on year
, ID
, and month
. Help would be appreciated. Here is a direct link to the data set I am trying to expand (.xls): http://db.tt/KeLRCzr9. Hopefully I've included enough information, but please let me know if there is any other information needed.