Michael Crowne
Michael Crowne

Reputation: 51

Stata Date Formatting

I am trying to use a tsset command and first have to format some dates. My code seems to skip over the hours of my input date. Instead of using the hour of the day, Stata uses the minute of the hour as the hour of the day, the seconds as minutes, and microseconds as seconds.

What am I doing wrong?

This is my code:

generate double sd = clock(datetimestamp,"YMD#hms##")
format sd %tcCCYY-NN-DD_HH:MM:SS.sss
sort sd

The input dates are ISO format datetime strings like:

datetimestamp = 2018-01-05 13:04:31.227488+00:00

The code generates a Stata date that looks like:

sd 2018-01-05 04:31:22.000

Notice that the timestamp indicates a time equal to 13:04:31.227488 and that Stata thinks the time is 04:31:22.000.

Upvotes: 0

Views: 182

Answers (1)

Michael Crowne
Michael Crowne

Reputation: 51

Fixed!

The first # in the first line of the above code had to be removed.

Upvotes: 1

Related Questions