Displayr's weighting tool is quite robust and has the ability to recompute a weighting scheme for each sub-sample within a grouping variable (such as a date, segment, wave, etc.) using the Recompute weights for field. However, sometimes you may need to apply a different weighting scheme (either different targets or variables) to each sub-sample. For example:
- You need to create weights based on regions within a country, but there are different regions for each country
- Some waves in your tracker have different target percentages or use different adjustment variables
- A category in an adjustment variable has 0 respondents within a wave or other sub-sample
- You want to weight just part of your data set.
You can manually figure out the population counts or overall weighting percentages and use those in a grid within the weighting tool, but many times that's a little complicated and tedious. The steps below use the more easily understood and commonly used target percentages for each adjustment variable. The general steps are:
Step 1. Create weights for each sub-sample
Step 3. Check the combined weight
See a Worked Example
Requirements
- Familiarity with the process in How to Configure a Weight from Variable(s), along with the requirements to configure a weight.
- A variable used to group respondents into the sub-samples (this can be a Nominal variable like Wave, Country, Region, or a Date variable that has been aggregated to the appropriate periods).
Method
Step 1. Create weights for each sub-sample
First, we will need to create a weight variable for each weighting scheme for our sub-samples. This ensures that the correct weighting scheme will be constructed for each sub-sample. Note that if you only want to weight part of your data set (so the "other" part has a weight of 0 and is excluded), you only need to create a weight for the subset you want to include.
- Set up the adjustment variables(s) for the weighting scheme of one of the sub-samples using Targets are > Percentages.
- Change Make weights sum to > target values (this will make the weighted base for each sub-sample 100 rather than the total sample of the data file, which is essential for later steps).
- Factor in the sub-sample grouping:
-
If you have the necessary sample for each target category across all sub-samples, you can select your grouping variable that identifies the sub-samples in the Recompute weights for field. It will compute weights for all sub-samples (note this is for all respondents, including those marked as missing data), but in a later step, we will pull off only the weight values from this variable for the appropriate sub-samples. In this example, the variable is called Interview Date
-
If you don't have respondents in each target for all sub-samples, for example, a wave doesn't have respondents in every category in the weighting scheme, or you are weighting on a region variable within different countries, click Additional adjustment variable set, select the variable that identifies your sub-samples, and set the particular sub-sample group associated with the weighting scheme to 100%. For example, below I'm only calculating this weighting scheme for July 2019 respondents, so I've added Interview Date as a separate adjustment variable and set the July 2019 date to 100:
- If you're not using or can't use the Recompute weights for feature, repeat the previous step until you have one weighting variable for each sub-sample.
-
If you have the necessary sample for each target category across all sub-samples, you can select your grouping variable that identifies the sub-samples in the Recompute weights for field. It will compute weights for all sub-samples (note this is for all respondents, including those marked as missing data), but in a later step, we will pull off only the weight values from this variable for the appropriate sub-samples. In this example, the variable is called Interview Date
Step 2. Combine the weights
Now we will pull off the values needed for each sub-sample from the appropriate weight variables created above, and combine them into one single weighting variable. The way you do this depends on whether you'd like 1) your sub-samples to have the same sample size or 2) to match the sample sizes of the original sub-sample groups.
Option 1: If you'd like your sub-samples' populations to be evenly weighted with the same sample size
- In the Data Sources tree, hover over a variable and click + > Custom Code > JavaScript > Numeric.
- Paste in the code below in the JavaScript Code box and edit as described in the comments (denoted by //):
//pull in sub-sample grouping variable (wave)
//replace wave with your own sub-sample grouping variable
var group = wave;
//////
//edit the if-else below to test for the appropriate code values and assign them
//the appropriate weight variable values
//if weighting part of a data set you will have only one group else NaN
/////
//if the respondent is in the 1st group use the weight for the 1st group
if (group== 1)
weight1; //replace with the sub-sample weight variable for the 1st group
//else if the respondent is in the 2nd group use the weight for the 2nd group
else if (group == 2)
weight2; //replace with the sub-sample weight variable for the 2nd group
//else if the respondent is in the 3rd group use the weight for the 3rd group
else if (group == 3)
weight3; //replace with the sub-sample weight variable for the 2nd group
//if any respondents don't fall into a group above, they will be given a blank weight
//which will filter them out when the weight is applied
else
NaN;
3. Give the new variable a label and check the Usable as a weight box in the object inspector to make it available in the Weight dropdowns.
Option 2: If you'd like each of your sub-samples' populations to be equal to the unweighted sample size within the unweighted data, you can combine the individual weights and gross up/down the respondent-level weights to balance out the sample size using a new R variable.
- In the Data Sources tree, hover over a variable and click + > Custom Code > R > Numeric.
- Paste in the code below in the R Code box and edit as described in the comments (denoted by #). Be sure to use the Label of each category in the "group" variable:
#replace YourGroupVariable with the variable used for the sub-sample
#with your cursor below you can click on it in the Data Sources tree
#to insert its name into the code
group = YourGroupVariable
#create an empty combined weight variable which we will fill in with values below
combweight = rep(NA,length(group))
######
#for each group/sub-sample, reference the correct individual weight and gross up/down
#based on the sample size of that group in the unweighted data
######
#hover over your group variable highlighted at the top of the code to confirm
#the labels R "sees" for the conditions below
#fill in the combined weight for respondents in the 1st group with the weight value of the
#weight for the 1st group (weight1) and gross up based on original sample size
#replace 1st with the category label of your first group and weight1 with the first's weight variable
combweight[group == "Group 1"] = weight1[group == "Group 1"] * sum(group == "Group 1",na.rm=T)/100
#replace 2nd with the label of your second group and weight2 with the second's weight variable
combweight[group == "Group 2"] = weight2[group == "Group 2"] * sum(group == "Group 2",na.rm=T)/100
#replace 3rd with the label of your third group and weight3 with the third's weight variable
combweight[group == "Group 3"] = weight3[group == "Group 3"] * sum(group == "Group 3",na.rm=T)/100
#any respondent not in the groups above will retain the initial missing value (NA)
#and be filtered out when the weight is applied, use combweight[group == "X"] = 1
#return the final result
combweight3. Give the new variable a label and check the Usable as a weight box in the object inspector to make it available in the Weight dropdowns.
Step 3. Check the combined weight
- Drag one of the adjustment variables you used in the weights onto the page to create a table.
- Cross it by the variable used to group the sub-samples.
- Select your combined weight variable from Step 2. Combine the Weights in the Data > Filters & Weight > Weight dropdown in the object inspector.
- Confirm the target percentages match for each sub-sample.
- If necessary, compare the Statistics > Below > Column Sample Size and Weighted Column Sample Size to confirm they are what you expect.
For example, in the table below, the combined weight uses a 50-50 target scheme for all months except July 2012 where a different 55-45 weighting scheme was used:
Worked Example
Weight each quarter of data based on age.
Targets within each quarter are as follows:
We want the final weighted population for each quarter to be equal to the # of respondents in the unweighted data.
To do so:
1. Create the weight for 1/1/2019
2. Create a weight for 4/1/2019. Duplicate the above weight and edit the Age and date targets.
3. Create the weight for 7/1/2019. Duplicate the above weight and edit the Age and date targets.
4. Insert the combined weight variable below the weight3 variable. To do so, click the + button to the right of weight3 and > Custom Code > R > Numeric.
5. Paste in R Code similar to below (line 2 has been edited to use the aggregated date values)
#identify group variable and use aggregated date names for each quarter using attr()
group=attr(date, "QDate")
#create empty combined weight variable
combweight = rep(NA,length(group))
#for each group, reference the correct individual weight and gross up based on subgroup sample size
combweight[group == "Jan-Mar 19"] = weight1[group == "Jan-Mar 19"] * sum(group == "Jan-Mar 19",na.rm=T)/100
combweight[group == "Apr-Jun 19"] = weight2[group == "Apr-Jun 19"] * sum(group == "Apr-Jun 19",na.rm=T)/100
combweight[group == "Jul-Sep 19"] = weight3[group == "Jul-Sep 19"] * sum(group == "Jul-Sep 19",na.rm=T)/100
#return final result
combweight
6. Press the Calculate button to run the code.
7. In the Object Inspector, in the Data > Properties, check Usable as a weight.
8. In the Object Inspector, select Data > Filters & Weight and apply the weight to the Age by Interview Date table.
The results confirm that the weights have been combined successfully.