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 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
Requirements
- 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).
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 sub-set you want to include.
- Setup the adjustment variables(s) for the weighting scheme of one of the sub-samples using Targets are > Percentages. For more information See Construct Weight
- 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-samples 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.
Option1: If you'd like your groups' populations to be evenly weighted, you can combine the individual weights directly using code similar to below.
To do so, create a JavaScript variable and paste it in the JAVASCRIPT CODE 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 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
//if wanting to leave a group unweighted, give them a value of 1
else NaN;
Option 2: 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 combweight[group == "X"] = 1
#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
Weight each quarter of data based on age, but where some quarters don't have all age groups, i.e. Q3 has 0 respondents who are 65 or more.
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 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
7. Give the new variable a Question Name
8. Click Add R Variable
9. Click W in the Tags column to make it available in the weight drop down
After applying it to your table, you can confirm the weight was combined successfully: