1

I trying out the plm package for some first difference estimation in R. As stated in the title I wonder how I can turn my POSIX dates like "2002-10-01" into values that are understood by plm's time index. I guess this means using integer values?

Here's what I tried so far:

panel.fd <- plm(y~X,index=c("datefield","id"),model="fd",data=z)
# returns
Error in pdim.default(index[[1]], index[[2]]) :
# when I convert my datefield to a factor, I get the same error...
z$t_idx <-as.factor(z$datefield) 
landroni
  • 2,902
  • 1
  • 32
  • 39
Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
  • `index` should be a vector of dates. At the moment you are offering a character vector. – IRTFM Feb 03 '11 at 01:15

2 Answers2

0

You can turn it into an integer value with unclass.

> unclass(Sys.time())
[1] 1296686673

If you divide that number by 86400 you would get the number of days since 1970-1-1.

The plm package does not use the time variable for much else than indexing purposes, so you are right in only needing an integer value here.

EDIT:

How about formating it and then converting:

> x <- as.POSIXlt("2011-02-02")
> x
[1] "2011-02-02"
> as.integer(format(x, "%Y%m%d"))
[1] 20110202
eyjo
  • 1,180
  • 6
  • 8
0

Section 4.1 of the Overview tha tis part of the plm package says:

As observed above, the current version of plm is capable of working with a regular data.frame without any further transformation, provided that the individual and time indexes are in the first two columns, as in all the example datasets but Wages. If this weren’t the case, an index optional argument would have to be passed on to the estimating and testing functions.

To my reading this implies that POSIXct dates should work fine.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • The example datasets all sport yearly dates... all of them are easy integer values.. and my problem does not apply. If you can point me to an example with monthly data – that´d be nice. – Matt Bannert Feb 02 '11 at 23:04
  • POSIXct seems to make a difference compared to POSIXlt, but still I get: duplicate couples (time-id) Error in pdim.default(index[[1]], index[[2]]) ... I will look if there's really a duplicate. – Matt Bannert Feb 02 '11 at 23:07
  • You do not have to explicitly indicate the individual and time indexes if they are in the first two columns. Other than that they just throw them into (a wrapper function of) tapply every now and then in the code, do not handle time formats. – eyjo Feb 02 '11 at 23:35