I have some data where the date and time is all together in one string variable. I originally tried to split and parse into two variables, and then convert to date and merge them back together, but couldn't get this final step to work properly.

And then after that, I am hoping to do some data cleaning, so something like
Code:
gen level_rank = "A" if level == 1 & newdatevar < June 12 at 15:01
(I'm not sure exactly how a joint date/time variable would look so obviously that last part is not real code).

What I've attempted is something like this:
Code:
split datetime, parse(" ")
generate newdate = date(datetime1, "mdy")
format newdate %td

replace datetime2 = subinstr(datetime2, ":", "", .)
destring datetime2, replace
gen level_rank = "A" if level == 1 & newdate < date("14jun2013", "dmy") & datetime2 < 1501
So basically, I convert the day/month/year into its own true date variable in Stata, and the time to a regular numeric variable, which still allows me to do a < but surely this is less efficient than creating one standard date + time variable in Stata and working with that...but I just can't seem to get that to work. My end goal is to be able to recode variables differently based on if they took the survey before June 12 at 15:01. Thanks much.



Some example data:


Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input str15 datetime byte(level wrx)
"6/14/2013 14:00" 1 15
"6/11/2013 15:00" 2 13
"6/12/2013 18:00" 1 14
"6/11/2013 15:00" 2 13
"6/14/2013 14:00" 1 50
"6/14/2013 14:00" 1 42
"6/14/2013 14:00" 1 23
"6/11/2013 15:00" 2 13
"6/12/2013 15:00" 2 51
"6/12/2013 18:00" 2 14
"6/12/2013 15:00" 2 42
"6/11/2013 15:00" 2 13
"6/14/2013 14:00" 1  2
"6/14/2013 14:00" 1 21
"6/14/2013 14:00" 1 31
"6/14/2013 14:00" 1 26
"6/12/2013 15:00" 2 21
"6/14/2013 14:00" 1 21
"6/12/2013 15:00" 2 28
"6/12/2013 18:00" 1 14
"6/12/2013 15:00" 2 28
"6/11/2013 15:00" 2 13
"6/12/2013 18:00" 2 14
"6/11/2013 15:00" 2 13
"6/14/2013 14:00" 1 23
"6/14/2013 14:00" 1 23
"6/14/2013 14:00" 1 21
"6/14/2013 14:00" 1 31
"6/14/2013 14:00" 1 28
"6/12/2013 15:00" 2 21
"6/14/2013 14:00" 1 21
"6/12/2013 15:00" 2  8
"6/12/2013 15:00" 2  4
"6/12/2013 15:00" 2 34
end