It is often desirable to choose the weighted sample size (Population) that is shown when a weight is applied to a table. For example, you may wish to have weights specified such that the Base Population matches the known population size of the country in which the study was conducted.
If you use the default settings when creating a weight in Displayr, the Base Population will match the Base n. The methods below can be used to choose the desired weighted sample size.
Method 1 - Set population/count targets
When creating the weight in Displayr, you can set targets by Population/Count numbers rather than percentages.
- Select Anything
> Weight.
- Select your Adjustment Variable(s).
- Set the Make weights sum to to sample size .
- Under the Targets are section, select Population/Count.
- Set your weight targets as normal, but instead of specifying targets as percentages, specify counts such that they add up to the desired population number.
Method 2 - Create a JavaScript variable
When the weights have been set up already, either in Displayr or in the raw data, then a JavaScript variable can be created to adjust the weights. This approach is only applicable when you are weighting up to a single population total, and when the number of cases is not going to change (in other cases it is better to use the method above):
- From the toolbar, select Anything
> Data > Variables > New > Custom Code > JavaScript - Numeric.
- In the Expression section, use the formula:
my_weight * 600 / 602
- Replace my_weight with the variable Name of your existing weight variable.
- Replace 600 with the desired weighted sample size.
- Replace 602 with the current sample size in your data file.
- Change the Label to something appropriate, for example, Population Adjusted Weight.
- Click the Calculate button to generate the weight value.
Method 3 - Create an R variable
You can also create an R variable to adjust the population of subgroups in your weight. 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. For example, if you need to have different weighting for USA and Canada, and they make up 300 and 600 respondents respectively, but each has a population of 100 in your weight -- you can use the following code to adjust the weighted populations for USA and Canada back to 300 and 600 while still retaining the specific weighting within each country. See How To Apply Different Weighting Structures To Sub-Samples for a full example.
From the toolbar, select Anything > Data > Variables > New > Custom Code > R Variable and paste in the code below.
# identify group variable
group = YourGroupVariable
#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 == "1"] = weight1[group == "1"] * sum(group == "1",na.rm=T)/100
combweight[group == "2"] = weight2[group == "2"] * sum(group == "2",na.rm=T)/100
combweight[group == "3"] = weight3[group == "3"] * sum(group == "3",na.rm=T)/100
combweight[group == "4"] = weight2[group == "4"] * sum(group == "4",na.rm=T)/100
#return final result
combweight
Replace YourGroupVariable on line 2 with the name of the group variable from your dataset and replace 1, 2, 3, etc with each group's label. Add/remove groups as needed.
Next
How to Configure a Weight from Variable(s)