Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str19 time_org float id "2009-01-03 18:15:05" 0 "2009-01-09 02:54:25" 1 "2009-01-09 02:55:44" 2 "2009-01-09 03:02:53" 3 "2009-01-09 03:16:28" 4 "2009-01-09 03:23:48" 5 "2009-01-09 03:29:49" 6 "2009-01-09 03:39:29" 7 "2009-01-09 03:45:43" 8 "2009-01-09 03:54:39" 9 end
Code:
gen year = substr(time_org,1,4) gen month = substr(time_org,6,2) gen day = substr(time_org,9,2) gen hour = substr(time_org,12,2) gen min = substr(time_org,15,2) gen second = substr(time_org,18,2) foreach x of varlist year month day hour min second { destring `x', replace } * gen time = mdyhms(month,day,year,hour,min,second)
Code:
gen lag1 = time[_n-1] gen period = (time-lag1)/1000 list in 1/10
1) It seems the results for time difference in seconds are incorrect.
2) If I set the datetime format with the code below, the time_org and time are different. How to fix it?
Code:
format time %tc
Code:
gen time = Cmdyhms(month,day,year,hour,min,second) format time %tC
0 Response to How do I get time difference (gap) in second?
Post a Comment