Hi all,
I have a string variable, date_str. I want to get these dates into %tc format to enable merging and/or appending this dataset to another dataset for which the equivalent variable is in %tc format.
I do this in two steps: 1) create date_td, a %td variable, based on date_str
2) create date_tc, a %tc variable, based on date_td
When I generate date_td, using the date() function in Stata 14.2, I get the expected results.
But when I then go on to generate a datetime variable, date_tc, using the cofd() function with date_td, some of the dates in date_tc are moved one second earlier than expected, which shifts the date portion of the tc variable to one whole day earlier than the original variable.
Code
Example of results
Questions
What is going on? Is this expected Stata behavior? If so, is there a way to generate a %tc variable where the date portion will always correspond to the date portion of the %td variable it is based on?
I have a string variable, date_str. I want to get these dates into %tc format to enable merging and/or appending this dataset to another dataset for which the equivalent variable is in %tc format.
I do this in two steps: 1) create date_td, a %td variable, based on date_str
2) create date_tc, a %tc variable, based on date_td
When I generate date_td, using the date() function in Stata 14.2, I get the expected results.
But when I then go on to generate a datetime variable, date_tc, using the cofd() function with date_td, some of the dates in date_tc are moved one second earlier than expected, which shifts the date portion of the tc variable to one whole day earlier than the original variable.
Code
Code:
*date_str is a str10 variable containing "YYYY-MM-DD" gen date_td= date(date_str,"YMD") format date_td %td gen date_tc = cofd(date_dt) format date_tc %tc
|
What is going on? Is this expected Stata behavior? If so, is there a way to generate a %tc variable where the date portion will always correspond to the date portion of the %td variable it is based on?

Comment