lokheart
lokheart

Reputation: 24655

How to convert date in Stata?

I have a date with a format like below, and I use R to convert it from string to date

date <- "20 Nov 2010 21:44:00:000"
strptime(date,"%d %b %Y %H:%M:%S")

I want to do it in Stata, but how? I tried this in Stata:

gen time_2 = date(time,"DMYhms#")

But it's not OK, why is that? Thanks.

Upvotes: 3

Views: 3359

Answers (1)

user872324
user872324

Reputation:

The date function converts dates expressed in days, months and years. For timestamps containing hours and seconds, you need the clock function. The new variable should be in double precision

gen double time_2 = clock(time,"DMYhms#")

Upvotes: 5

Related Questions