Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: datetime conversion from R to Stata


From   Hiroyuki Kawakatsu <[email protected]>
To   [email protected]
Subject   st: datetime conversion from R to Stata
Date   Fri, 24 Jan 2014 11:50:59 +0000

Hi,

Prof Brian Ripley (R-core member) `speculated'[1] that the
datetime conversion command from R to Stata in

http://www.stata.com/help.cgi?datetime#s11

should use tc() rather than tC(). There are two other typos in

. gen double statatime = rtime - tC(01jan1970 00:00)

which I suspect should be

. gen double statatime = rtime*1000 + tc(01jan1970 00:00)

Can someone in the know confirm this?
I used the following test. I generated the data file in R as

x = seq(Sys.time(), by="sec", length.out=10);
x = data.frame(posixct=x, rnum=as.numeric(x));
write.table(x, "xxx.csv", sep=",", row.names=FALSE)

and read it in Stata using the suggested command
(with the two typos corrected):

> insheet using xxx.csv, clear names;
(2 vars, 10 obs)
. gen double xbigc = rnum*1000 + tC(01jan1970 00:00);
. format xbigc %tC;
. gen double xc = rnum*1000 + tc(01jan1970 00:00);
. format xc %tc;

. desc;
Contains data
  obs:            10
 vars:             4
 size:           390
-------------------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
-------------------------------------------------------------------------------------------------
Sorted by:
     Note:  dataset has changed since last saved

. list, clean;
                   posixct         rnum                xbigc
        xc
  1.   2014-01-24 05:08:18   1390540098   24jan2014 05:07:53
24jan2014 05:08:18
  2.   2014-01-24 05:08:19   1390540099   24jan2014 05:07:54
24jan2014 05:08:19
  3.   2014-01-24 05:08:20   1390540100   24jan2014 05:07:55
24jan2014 05:08:20
  4.   2014-01-24 05:08:21   1390540101   24jan2014 05:07:56
24jan2014 05:08:21
  5.   2014-01-24 05:08:22   1390540102   24jan2014 05:07:57
24jan2014 05:08:22
  6.   2014-01-24 05:08:23   1390540103   24jan2014 05:07:58
24jan2014 05:08:23
  7.   2014-01-24 05:08:24   1390540104   24jan2014 05:07:59
24jan2014 05:08:24
  8.   2014-01-24 05:08:25   1390540105   24jan2014 05:08:00
24jan2014 05:08:25
  9.   2014-01-24 05:08:26   1390540106   24jan2014 05:08:01
24jan2014 05:08:26
 10.   2014-01-24 05:08:27   1390540107   24jan2014 05:08:02
24jan2014 05:08:27

.   /*close log file*/
> capture log close;

[1] https://stat.ethz.ch/pipermail/r-devel/2014-January/068271.html

-- 
+---
| Hiroyuki Kawakatsu
| Business School, Dublin City University
| Dublin 9, Ireland. Tel +353 (0)1 700 7496
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index