Hi,

I want to convert some string variable to datetime format using the clock() function (Stata 14.2 MP). Here is the code I run:

gen time_login_tc = clock(time_login, "YMD hms")
gen time_login_tC = Clock(time_login, "YMD hms")

format time_login_tc %tc
format time_login_tC %tC


The left column (time_login) depicts the original string variable. The center and right column the datetime variables that have been converted with clock() and Clock() respectively.

time_login time_login_tc time_login_tC
2019-01-21 09:43:00 21jan2019 09:43:34 21jan2019 09:43:07
2019-01-21 11:00:28 21jan2019 11:00:02 21jan2019 10:59:35
2019-01-21 11:05:03 21jan2019 11:04:24 21jan2019 11:06:08
2019-01-21 11:06:49 21jan2019 11:06:35 21jan2019 11:06:08
2019-01-21 11:40:23 21jan2019 11:39:21 21jan2019 11:41:05
2019-01-21 12:22:33 21jan2019 12:23:02 21jan2019 12:22:35
2019-01-21 12:25:34 21jan2019 12:25:13 21jan2019 12:24:46



The problem is that neither conversion gives me correct results. They are off by a couple of seconds in random directions and I can't detect any systematic patterns. I would appreciate hearing any ideas about what might be going on.

Thanks,
Andreas

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str19 time_login
"2019-01-21 09:43:00"
"2019-01-21 11:00:28"
"2019-01-21 11:05:03"
"2019-01-21 11:06:49"
"2019-01-21 11:40:23"
"2019-01-21 12:22:33"
"2019-01-21 12:25:34"
end