dtV <- seq(from=as.Date("1975-01-01"),by='1 month',length=372) x$dt <- dtV[x$id]
HTH, Eric On Mon, Sep 2, 2019 at 8:36 PM Miluji Sb <miluj...@gmail.com> wrote: > Dear all, > > I have a panel data with a large number of groups and the cumulative number > of months (1 - 372) for January 1995 to December 2005. My goal is to > extract the corresponding month and year for each observation. > > I tried the following; > > ### > x %>% > group_by(id) %>% > do( data.frame(., Date= seq(.$startdate, > as.Date('1975-01-01'), by = '1 month'))) > > However, I get the following error; > > ### > Error in seq.default(.$startdate, as.Date("1975-01-01"), by = "1 month") : > 'from' must be of length 1 > > Essentially, I want to convert the month number (1-372) to January 1975 to > December 2005 by ID. Is that possible? Any help will be highly appreciated. > > ### Data ### > x <- structure(list(id = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), month = > c(1L, > 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), startdate = structure(c(1L, > 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "1975-01-01", class = "factor"), > enddate = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = > "2005-12-31", class = "factor")), class = "data.frame", row.names = c(NA, > -9L)) > > Cross-posted in Statalist - however, Stata seems to have a very inflexible > date-time structure. > > Best regards, > > Milu > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.