Hi all,
I'm using Stata v13.1 in Windows and on a network installation. I have a variable (x526_) containing a string date time value such as
05/01/2014 10:15
I want to split this variable and then generate two extra numeric variables containing 'date' and 'time'.
I can do this using the following code (I loop through a number of variables):
split x526_
foreach var of varlist x526_ {
g `var'_date = date(`var', "DMYhm")
replace `var'_date = date(`var', "DMY") if `var'_date==. & `var'!=""
format `var'_date %td
g `var'_time = clock(`var', "DMYhm")
format `var'_time %tc_HH:MM
}
However, I observe that when generating the time(clock) aspect of the date time variable, Stata is not converting the string date time in an exact form - i.e. it is either adding or subtracting a minute from the old time variable when creating the new time variable - this does not appear to be consistenly applied either. This could have important consequeneces to my analysis. Anyone have a clue what is going on here?
Here are some examples from the editor window:

If I look at the final column shown below (z526__time), the full contents of the entry for the penultimate record is 16jan2012 07:44:12 - and I'm surprised as I don't actually supply this infoirmation from the original string value.
Thanks
Tim
I'm using Stata v13.1 in Windows and on a network installation. I have a variable (x526_) containing a string date time value such as
05/01/2014 10:15
I want to split this variable and then generate two extra numeric variables containing 'date' and 'time'.
I can do this using the following code (I loop through a number of variables):
split x526_
foreach var of varlist x526_ {
g `var'_date = date(`var', "DMYhm")
replace `var'_date = date(`var', "DMY") if `var'_date==. & `var'!=""
format `var'_date %td
g `var'_time = clock(`var', "DMYhm")
format `var'_time %tc_HH:MM
}
However, I observe that when generating the time(clock) aspect of the date time variable, Stata is not converting the string date time in an exact form - i.e. it is either adding or subtracting a minute from the old time variable when creating the new time variable - this does not appear to be consistenly applied either. This could have important consequeneces to my analysis. Anyone have a clue what is going on here?
Here are some examples from the editor window:
If I look at the final column shown below (z526__time), the full contents of the entry for the penultimate record is 16jan2012 07:44:12 - and I'm surprised as I don't actually supply this infoirmation from the original string value.
Thanks
Tim
Comment