We need to add the difference between SPSS’s base and Stata’s base, which is tc(14oct1582 00:00) – tc(01jan1960 00:00), but tc(01jan1960) is definitionally 0, so that just leaves tc(14oct1582 00:00). Adding tc(14oct1582 00:00) accounts for the differing bases.įunction tc() returns the specified datetime as a Stata datetime, which is to say, the number of milliseconds between the specified datetime and 01jan1960 00:00:00.000. Multiplying by 1,000 converts from seconds to milliseconds. To convert SPSS datetimes to Stata datetimes, type SPSS stores both dates and datetimes as the number of seconds since 14oct1582 00:00:00, assuming 86,400 seconds/day. It is important that variables containing SAS datetimes, such as sastime above, be imported as doubles into Stata. Thus, all that’s necessary is to multiply SAS datetimes by 1,000 and attach a %tc format to the result, SAS stores datetimes as the number of seconds since 01jan1960 00:00:00, assuming 86,400 seconds/day. SAS stores dates as the number of days since 01jan1960, the same as Stata: Below are conversion rules for SAS, SPSS, R, Excel, and Open Office. It is usually possible to adjust the numeric date or datetime values to the sentinel date and units that Stata uses.
#Possible spss code error software#
It sometimes happens that you need to process in Stata data imported from other software and end up with a numerical variable recording a date or datetime in the other software’s encoding. Other packages use different choices for bases and units. Stata stores dates as the number of days since 01jan1960, and datetimes as the number of milliseconds since 01jan1960 00:00:00.000. Most software stores dates and times numerically, as durations from some sentinel date, but they differ on the sentinel date and on the units in which the duration is stored.