I know that this is covered elsewhere, but I can't get the code to work. I have dates that look like this (let's call this variable "var"):
Examples: "2019-08-19 12:16:00"
"2020-11-19 20:41:21"
"2021-11-22 16:14:37"
"2022-08-19 11:08:01"
I try the following code (I have tried about two dozen variations of this, all with the same result):
gen double var_n = clock( var , "YMDHMS")
The result is that var_n consists only of missing values, so none of the dates are converted. I have seen this behavior typically if the format is not correctly specified, but I have tried every variation on the format specification that I can think of, and nothing works. Other variables being converted where they are dates without times (using different code, but a similar approach) works fine. I feel that I must be missing something obvious, but I am just not seeing it. I'm hoping someone can quickly see what I am doing wrong? Thanks in advance for any help!
Examples: "2019-08-19 12:16:00"
"2020-11-19 20:41:21"
"2021-11-22 16:14:37"
"2022-08-19 11:08:01"
I try the following code (I have tried about two dozen variations of this, all with the same result):
gen double var_n = clock( var , "YMDHMS")
The result is that var_n consists only of missing values, so none of the dates are converted. I have seen this behavior typically if the format is not correctly specified, but I have tried every variation on the format specification that I can think of, and nothing works. Other variables being converted where they are dates without times (using different code, but a similar approach) works fine. I feel that I must be missing something obvious, but I am just not seeing it. I'm hoping someone can quickly see what I am doing wrong? Thanks in advance for any help!

Comment