When analyzing trended data, you may want to isolate and compare non-adjacent time periods, for example, current quarter vs. same quarter last year.
You can create an Ordinal variable from a Date/Time variable that can be used to compare two time periods of your choosing.
For example, you can reduce your crosstab from looking at all time periods:
To a reduced set of two time periods to compare against each other:
This article details how to create custom time periods to be compared.
Requirements
- A data set loaded into Q with a Date/Time variable.
Method
- Select the Date/Time variable in the Variables and Questions tab.
- Go to Automate > Browse Online Library > Create New Variables > Contrast Periods. This will create a categorical variable.
- To edit the variable, right-click the variable in the Variables and Questions tab then select Edit R Variable...
- On the right side of the window, set the Date aggregation to whichever duration you prefer (week, month, quarter, etc.).
- Select the periods that you would like to contrast in the Compare and Versus fields.
- Click Update R Variable.
This variable can now be used to show and test for changes between the selected periods.
Technical Details
The date periods available in the Compare and Versus menus are generated at the time you first use this tool. They are evaluated relative to the dates in your data set, and they are extended for a period of three years to allow you to continue to use the same Contrasts as you continue to update your data set with new data.
The Contrasts variable contains two categories, but only one of them is shown. Date values which are not in the Compare or Versus periods are assigned a missing value. The resulting statistical tests are then equivalent to a comparison between Compare and Versus.