Stata command to shift time zones

SurveyCTO exports time and datetime fields relative to the time zone of the exporting computer – not the time zone of the data-collection device. If data is collected in more than one time zone, converting date and time values to a single relative time zone can be advantageous. However, there are several reasons you might want to change the time zone of your exported data. In this article, we explain the different strategies you may use to achieve this, including the Stata command sctorezone. This command changes the time zones of datetime fields formatted according to the SurveyCTO .do file template (i.e., in %tc format), and time fields using SurveyCTO standard format (e.g. "12:34:56 PM").

This SurveyCTO resource for Stata users was developed by William Blackmon, Research Manager at IPA (Innovations for Poverty Action).

Using this Stata command, you will be able to:

  1. Specify which datetime and time fields you would like the shift time zones for, if not all.
  2. Shift time zones in one of two ways:
    • Setting the number of hours you would like to shift forwards/backwards.
    • Specifying a calculate field that stores the actual time zone of the data collector.

Getting started

The sctorezone command is included in the scto Stata package, where you can find other Stata commands to make the most of data collected using SurveyCTO. All information and code is available at

If you’ve NEVER installed our scto package...

To install, enter ssc install scto in the Stata command window.

If you’ve ALREADY installed our scto package...

To update, enter ado update scto, update in the Stata command window.

To read the associated documentation, enter help sctorezone into the Stata command window.


To run the command, follow the syntax below, and adjust it according to your dataset:

sctorezone shift [if] [in] , force [only(varlist) | exclude(varlist)]

The shift parameter indicates how much to shift your datetime and/or time fields. Shift can be formatted for manual or automatic re-zoning:

  • Manual: set the number of hours to shift datetime and time variables forwards (use +) or backwards (use -). For example, sctorezone +5.5, force or sctorezone -3, force.
  • Automatic: include a calculate field in your form design that calculates the data collector’s time zone at the start time of the survey: format-date-time(${starttime}, '%Y-%b-%e %H:%M:%S'). When exporting data, this field won’t be shifted according to the time zone of the exporting computer because all calculate fields are considered strings or numbers, not datetime or time fields, regardless of their content. You can then use this calculate field in the command to shift all datetime and time fields to the same time zone of the data collector’s device, e.g., sctorezone starttime_calculate, force. This command will calculate the difference between the exported starttime and starttime_calculate fields, and shift time zones accordingly.


Example 1

sctorezone -3, only(starttime) force

In this example, sctorezone manually shifts (only) the variable “starttime” backward three hours.

Example 2

sctorezone +5.5, exclude(timefield) force

In this example, sctorezone manually shifts all datetime and time variables forward five and a half hours, excluding the variable named “timefield”.

Example 3

sctorezone starttime_calculate, force

In this example, sctorezone automatically shifts the times of all datetime and time variables according to the string variable “starttime_calculate”, which is a SurveyCTO calculate field with the following calculation expression: format-date-time(${starttime}, '%Y-%b-%e %H:%M:%S').

We hope that you find this command useful! Please consider sharing your experiences in our user forum.

Do you have thoughts on this support article? We'd love to hear them! Feel free to fill out this feedback form.


Article is closed for comments.