As the times are listed as string variables, I first have to convert them to clock variables. However, I convert the string to a clock variable, the string and the clock variable are not providing the same seconds value. Please see the code I am using at the end of post, and note that "time1" and "rtime1" do not agree in terms of seconds. (I also cannot change how the dates are being inputed, as they have been given to me as string variables).
A secondary problem I am having is converting the clock variable to a date format so that I can compare dates (I want to know if "time1"="time2"), but first I would like to know why "time1" and "rtime1" do not agree.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str19(time1 time2) "2020-12-13 02:58:57" "2020-12-13 03:20:51" "2020-12-13 02:58:58" "2020-12-13 03:20:53" "2020-12-13 15:10:16" "2020-12-13 15:51:29" "2020-12-13 15:10:43" "2020-12-13 15:51:24" "2020-12-13 15:16:09" "2020-12-13 15:51:15" "2020-12-13 15:39:52" "2020-12-13 16:11:05" "2020-12-13 15:49:06" "2020-12-13 16:25:31" "2020-12-13 16:38:09" "2020-12-13 17:09:48" "2020-12-13 16:42:47" "2020-12-13 17:12:52" "2020-12-13 16:42:49" "2020-12-13 17:12:55" "2020-12-13 16:42:50" "2020-12-13 17:12:58" "2020-12-13 16:45:41" "2020-12-13 17:15:03" "2020-12-13 16:54:41" "2020-12-13 17:43:29" "2020-12-13 17:09:09" "2020-12-13 17:44:02" "2020-12-13 17:17:23" "2020-12-13 18:01:57" "2020-12-13 17:17:57" "2020-12-13 18:01:52" "2020-12-13 17:23:47" "2020-12-13 18:01:48" "2020-12-13 17:36:47" "2020-12-13 18:27:42" "2020-12-13 17:41:09" "2020-12-13 19:01:47" "2020-12-13 18:19:16" "2020-12-13 19:09:43" "2020-12-13 18:27:13" "2020-12-13 19:09:34" "2020-12-13 18:27:14" "2020-12-13 19:09:40" "2020-12-13 18:32:01" "2020-12-13 19:09:38" "2020-12-13 18:56:54" "2020-12-13 20:00:49" "2020-12-13 18:56:57" "2020-12-13 20:06:45" "2020-12-13 18:56:49" "2020-12-13 20:02:07" "2020-12-13 18:57:34" "2020-12-13 20:14:05" "2020-12-13 19:20:09" "2020-12-13 19:54:11" "2020-12-13 19:20:10" "2020-12-13 19:54:14" "2020-12-13 19:20:12" "2020-12-13 19:54:19" "2020-12-13 19:21:54" "2020-12-13 19:54:17" "2020-12-13 19:59:40" "2020-12-13 22:07:44" "2020-12-13 19:53:12" "2020-12-13 20:43:48" "2020-12-13 20:05:28" "2020-12-13 21:49:55" "2020-12-13 20:08:00" "2020-12-13 21:10:58" "2020-12-13 20:08:03" "2020-12-13 21:10:51" "2020-12-13 20:11:51" "2020-12-13 21:51:23" "2020-12-13 20:12:49" "2020-12-13 22:06:50" "2020-12-13 20:12:14" "2020-12-13 22:08:10" "2020-12-13 20:13:03" "2020-12-13 22:10:38" "2020-12-13 20:13:41" "2020-12-13 22:12:46" "2020-12-13 20:14:27" "2020-12-13 21:10:46" "2020-12-13 20:55:04" "2020-12-13 21:20:47" "2020-12-13 21:04:09" "2020-12-13 21:27:16" "2020-12-13 21:23:08" "2020-12-13 22:03:05" "2020-12-13 21:23:11" "2020-12-13 22:03:03" "2020-12-13 21:23:13" "2020-12-13 22:02:59" "2020-12-13 21:23:15" "2020-12-13 22:02:56" "2020-12-13 21:23:19" "2020-12-13 22:02:52" end
format rtime1 %tC
. list *time1 in 1/5, noobs separator(0)
+------------------------------------------+
| time1 rtime1 |
|------------------------------------------|
1. | 2020-12-13 02:58:57 13dec2020 02:58:14 |
2. | 2020-12-13 02:58:58 13dec2020 02:58:14 |
3. | 2020-12-13 15:10:16 13dec2020 15:10:03 |
4. | 2020-12-13 15:10:43 13dec2020 15:10:03 |
5. | 2020-12-13 15:16:09 13dec2020 15:16:36 |
+------------------------------------------+
Thank you for any assistance.
Best,
Christina
0 Response to Converting string var to clock var, where seconds don't agree
Post a Comment