This article describes how to go from tables that show all data...
...to tables that only show data for the last 2 periods, for example:
Requirements
A data set that includes a Nominal (also known as categorical) wave variable. In this example, we have a variable called Wave that tells us what quarter the survey was completed. Waves must be in ascending order when shown in a table, like:
Instructions for how to convert date/time variables to nominal variables can be found here: How to Create a Categorical Variable from a Date/Time Variable.
Method
1. In the Data Sources tree, hover over any variable and click the Plus (+) then select Custom Code > R - Numeric.
2. Paste the code below into the R Code editor:
unique.waves = levels(Wave) #Get wave categories
last.two.waves = unique.waves[(length(unique.waves)-1):length(unique.waves)] #Find last 2 waves
Wave %in% last.two.waves
- The above code gets the levels or categories from the Wave variable. You will need to replace Wave with the Name of your nominal wave variable.
- It then identifies the last 2 wave categories. Note, this code assumes the waves are in the correct order.
- Finally, we return TRUE or FALSE based on whether the data matches these 2 wave categories.
3. Tick Usable as a filter.
4. Give the filter a Name and Label in the General tab of the object inspector.
5. OPTIONAL: Update the Structure to Nominal or Ordinal in the Data tab of the object inspector.
6. Select the relevant outputs and apply this filter via Data > Filters & Weight > Filter(s) in the object inspector.
Next
How to Create a Custom Numeric R Variable
How to Build Tables that Automatically Filter to the Latest Periods
How to Create a Categorical Variable from a Date/Time Variable