I am trying to create a new variable that has the date (bedtime_date) and time (q4_time_outofbed) information.
I used the date and clock function to create the new date and time variables, and each looks correct. However, when I merged them together (bed_datetime), it gives me the correct month and day, but the wrong year.
The storage types for bedtime_date and q4_time_outofbed are double.
I cannot figure out why. Please advise!
Code:
* date; gen double bedtime_date2=date(bedtime_date, "MDY") drop bedtime_date rename bedtime_date2 bedtime_date * time; gen double oob=clock(q1_time_lightsout, "hms") drop q1_time_lightsout rename oob q1_time_lightsout * date+time; gen double bed_datetime=bedtime_date*24*60*60*1000+q1_time_lightsout format bedtime_date %tdNN/DD/CCYY format q1_time_lightsout %tcHH:MM:SS format bed_datetime %tcNN/DD/CCYY_HH:MM:SS list bedtime_date q1_time_lightsout bed_datetime in 1/10
0 Response to Creating a new variable with date and time together
Post a Comment