Quantcast
Channel: The Stata Blog - Latest Comments
Viewing all articles
Browse latest Browse all 1129

Re: A tour of datetime in Stata

$
0
0

Thank you for your post. The explanation is clear and makes sense, but I am not able to make it work on my own dataset.

I have a variable "delivery" which is type double, format %tc [03jan2010 14:19:59].

I am interested in extracting three variables from this: year, day of the week, and time. I have tried multiple codes and am unable to figure out how to extract the year, much less anything else.

I have tried destringing "delivery" and creating a new variable "delivery_str": 1578147600000. "delivery_str" is type str13, format %19s. I have also created an additional variable "delivery_float" type float, format %td.

I have tried the following codes:
. gen year=date(delivery_str,"DMY####")
(2,909 missing values generated) [so an empty dataset]

gen year=date(delivery"DMY###")
type mismatch
r(109);

. gen year=date(delivery_float,"DMY####")
type mismatch
r(109);

format %td delivery_float
list delivery_float
which shows my data in this format: 1.79e+12

I can't make heads or tails of this and asked another researcher versed in stata for help last night. He was not able to assist and suggested I come on here and ask for help.

Please help.
Thank you in advance.

Thank you.


Viewing all articles
Browse latest Browse all 1129

Trending Articles