I am writing to ask for your help with generating date/time variable, which I am struggling for. The variables I have is as follows.
Month: Month
Date: Date
StartH: Start Hour
StartM: Start Minute
EndH: End Hour
EndM: End Minute
AM: (dummy) AM=1, PM=0
What I would like to do is to create the variable that I can see all the information including month, date, start hour, start minute, end hour, end minute, AM/PM. I simply altered from numeric to string all the variables, but it does not look any good. The code I used is:
Code:
tostring AM, replace replace AM="AM" if AM==1 replace AM="PM" if AM==0 gen startt=string(Month)+"/"+string(Date)+""+string(StartH)+":"'+string(StartM)+""+string(AM) gen endt=string(Month)+"/"+string(Date)+""+string(EndH)+":"'+string(EndM)+""+string(AM)
Code:
gen duration=endt-startt
Could you please let me know the code for this matter?
I attach the data extracted by dataex from the datafile below. I really appreciate your help in advance.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(Month Date StartH StartM EndH EndM AM) 7 9 9 10 9 19 1 7 10 2 52 2 57 0 . . . . . . . 7 8 4 15 4 20 0 7 9 16 50 17 23 0 7 6 2 33 2 52 0 7 7 9 0 9 15 1 7 10 6 55 7 23 0 7 8 8 5 8 36 0 7 8 11 30 11 31 1 7 8 6 14 6 19 0 . . . . . . . 7 7 8 0 8 10 1 7 11 2 10 2 36 0 7 11 9 45 10 12 1 7 9 6 10 6 14 1 . . . . . . . 7 7 5 58 6 4 0 7 7 6 37 7 15 0 7 10 1 0 1 35 0 7 8 5 15 5 28 0 . . . . . . . . . . . . . . 7 10 10 3 10 8 1 7 9 11 15 11 42 1 7 9 10 30 11 10 1 7 8 7 24 7 26 0 7 7 5 15 6 0 0 . . . . . . . 7 8 8 35 8 40 1 7 10 9 30 9 44 1 7 9 8 0 8 5 99 7 9 10 15 10 45 1 . . . . . . . 7 10 9 0 9 40 1 99 99 99 99 99 99 99 . . . . . . . 7 6 1 30 2 10 0 7 9 9 0 9 5 1 7 10 8 15 8 38 1 7 10 9 5 9 45 1 7 7 7 40 8 20 0 7 8 12 0 12 30 99 7 9 11 43 11 56 1 7 11 5 4 5 25 0 . . . . . . . end label values CalAP_e_id1 CalAP_e_id1_label label def CalAP_e_id1_label 0 "PM", modify label def CalAP_e_id1_label 1 "AM", modify
0 Response to Generate Date/Time Variable
Post a Comment