Requirements
Data collected over time (e.g. quarters, weeks, or some other ordinal information). For example:
Method
How do you enable comparing to the previous period?
You can enable this feature by going to either the Table or Project options via
- Edit > Table Options
or
- Edit > Project Options > Customize.
- Within the Table/Project Options click the Statistical Assumptions tab. On the bottom left is a drop-down menu for Date questions, where you can set it to compare to previous period.
Whether this setting is on or off, it will be clarified in the footer of the table by default when you use a Date Question. It will either say “Significance Testing: Compare to previous period” or “Significance Testing: Compare to rest of data”.
How do you turn a categorical variable into a Date question?
Suppose you have a categorical variable called “wave”. It encodes the wave as (1 = wave1, 2 = wave2, 3 = wave3, and 4 = wave4). You want to turn “wave” into a proper date-time variable, to use it as a Date question. This is where a JavaScript variable sorts you out.
You can make a JavaScript variable by
- Create > Variables and Questions > Variables > JavaScript Formula > Numeric (this is also available via a right-click in the Variables and Questions tab).
- In the JavaScript Variable expression window, you’ll use a simple IF AND ELSE IF expression combined with Q’s Q.EncodeDate() function, like the following:
if (wave == 1) Q.EncodeDate(2018,01,31);
else if (wave == 2) Q.EncodeDate(2018,02,28);
else if (wave == 3) Q.EncodeDate(2018,03,31);
else if (wave == 4) Q.EncodeDate(2018,04,30);
In this case, we’re reassigning each of the wave variables to the last day of the month in 2018 from Jan to April respectively. You could set it to any date, as long as it’s in the format (yyyy,mm,dd). As with all JavaScript variables, be sure it checks out in the Preview Panel at the bottom of the window. Push OK to save the variable. Our video on JavaScript variables demonstrates this process.
You now have a new numeric variable in your Variables and Questions tab. Change the variable type to “Date/Time” and you’ll now have a new Date/Time question. Be sure to check the Values to set your desired aggregation.
This Date/Time question will now be available for you to use in your cross-tabs. And, pertinently, for use with the statistical testing against a previous period!
Comments
0 comments
Article is closed for comments.