Q'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 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:
- Familiarity with the process of 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).
Step 1. Create weights for each sub-sample
- Setup the targets for the first group (see Construct Weight) where each Weight set has the group variable listed as the Target column question(s) and the remaining groups are given 0 targets
- Uncheck Force sum of weights to equal sample size for all Weight sets (this will make the Population for each group = 100)
- Change the Variable Name of the new weight variable to weight1
- Repeat the above steps for each of the groups
- Click the W in the Tags column for the new combined weight variable in the Variables and Questions tab
Step 2. Combine the weights
If you'd like your groups' populations to be evenly weighted, you can combine the individual weights directly using code similar to below.
Replace the group with the group variable from your dataset and add/remove groups as needed.
//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 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
//if wanting to leave a group unweighted, give them a value of 1
If you'd like your groups' populations to equal the group's 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.
To do so, create an R variable and paste it in the R CODE below.
#replace YourGroupVariable with the variable used for the sub-sample
#with your cursor below you can click on it in the Data Sets 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 label of your first group and weight1 with the first's weight variable combweight[group == "1st"] = weight1[group == "1st"] * sum(group == "1st",na.rm=T)/100
#replace 2nd with the label of your second group and weight2 with the second's weight variable combweight[group == "2nd"] = weight2[group == "2nd"] * sum(group == "2nd",na.rm=T)/100 #replace 3rd with the label of your third group and weight3 with the third's weight variable
combweight[group == "3rd"] = weight3[group == "3rd"] * sum(group == "3rd",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 #if wanting to leave a group unweighted, use = 1 after subsetting their group
#return the final result combweight
Step 3. Check the combined weight
- Create a new table, and select one of the adjustment variables in the Blue dropdown.
- In the Brown dropdown, cross it by the variable used to group the sub-samples.
- Select your combined weight variable from Step 2. Combine the Weights in the Weight dropdown.
- Confirm the target percentages match for each sub-sample.
- If necessary compare the Statistics - Below > Column n and Column Population to confirm they are what you expect.
A Worked Example
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 Q1
2. Create the weight for Q2
3. Create the weight for Q3
4. On the Variable and Questions tab right click on a row and select Insert Variable(s) > R Variable
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 blue play button to run the code
8. Click Add R Variable
9. Click W in the Tags column to make it available in the weight drop down