0
votes

I am attempting to round times to the nearest 15 minute interval in Stata, so for instance Dec 31, 2017 23:58 would become Jan 01, 2018 00:00. I have time stored (based on my understanding of the documentation) as the number of milliseconds since the start of 1960. So I thought this would do it:

gen round = round(datetime, 60000*15)

However, this doesn't quite work. For instance Nov 03, 2017 19:45:27 becomes Nov 03, 2017 19:46:01, when I think I should become 19:45:00. Does anyone know what I'm missing here?

1
Stata datetime values need to be stored as double; your generate command should begin gen double rounduser4690969

1 Answers

2
votes

Let's show a worked example illustrating my comment that you need to store datetime values as double rather than float.

. clear

. set obs 1
number of observations (_N) was 0, now 1

. gen double datetime = clock("Nov 03, 2017 19:45:27","MDYhms")

. gen round_f = round(datetime, 60000*15)

. gen double round_d = round(datetime, 60000*15)

. format datetime round_f round_d %tc

. list, clean noobs

              datetime              round_f              round_d  
    03nov2017 19:45:27   03nov2017 19:46:01   03nov2017 19:45:00