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:
A data set that includes a Nominal wave variable. In this example, we have a variable called Wave that tells us what quarter the survey was completed.
1. Select your data set in the Data Sets tree.
2. Go to Anything > Data > Variables > New > Custom Code > R - Numeric in the toolbar.
3. Paste the below under Properties > R CODE in the object inspector:
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.
- 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.
4. Tick Usable as a filter.
5. Select the relevant outputs and apply this filter via Inputs > FILTERS & WEIGHT > Filter(s) in the object inspector.