Hi everyone,
I'm trying to shift a datetime (format %tc) variable by an hour. Since tc variables are stored in milliseconds from Jan 1 1960, I assumed I needed to simply add the number of milliseconds in an hour to the variable, 60*60*1000.
Starting with some dummy data...
Then I'll create a new variable, tcvar_shifted, with 60*60*1000 added to it
My original tcvar was "21jan2020 11:24:55", and my shifted variable is "21jan2020 12:23:57".
So it almost works, but for some reason seems to be adding 58 seconds less than an hour. Any ideas why this might be?
I'm trying to shift a datetime (format %tc) variable by an hour. Since tc variables are stored in milliseconds from Jan 1 1960, I assumed I needed to simply add the number of milliseconds in an hour to the variable, 60*60*1000.
Starting with some dummy data...
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double tcvar 1895225095000 end format %tc tcvar
Then I'll create a new variable, tcvar_shifted, with 60*60*1000 added to it
Code:
gen tcvar_shifted = tcvar + 60*60*1000 format tcvar_shifted %tc list
So it almost works, but for some reason seems to be adding 58 seconds less than an hour. Any ideas why this might be?
Comment