See Crunch Automation basics for more information.
The CREATE WEIGHT command allows you to create a numeric variable, which you can subsequently use as a weight variable using the SET WEIGHT command.
Weighting is performed by the RAKE function (raking or ‘rim weighting’). This allows you to use use multiple categorical variables as input and set different targets for each of the categories. The targets must sum to one exactly for each variable and you can specify the categories either by their code (category id) or by their label.
You can cap the weights using the TRIM argument.
CREATE WEIGHT RAKE alias (TARGETS code|"label"=float, ..., code|"label"=float), ... alias (TARGETS code|"label"=float, ..., code|"label"=float) [TRIM MIN=float MAX=float] AS alias [TITLE "string"] [DESCRIPTION "string"] [NOTES "string"];
In the 2019 Mobile Broadband and Home Technology datafile example, there are a couple of numeric weighting variables already in the raw SPSS file. However, we might like to create our own. In this example, we may want to weight to Census Bureau Region and Gender. These two variables, unweighted, sit side by side in the following:
We may want to weight Census Bureau targets and 50/50 split in Gender. We can create a weighting variable that does just that with the following script:
CREATE WEIGHT RAKE cregion (TARGETS "Northeast"=0.170, "Midwest"=0.208, "West"=0.383 , "South"=0.239), sex (TARGETS “Male”=0.5, “Female”=0.5) AS weight_cregion_gender TITLE "Weight - Region & Gender" DESCRIPTION "Census Bureau 2019 targets with 50/50 Gender”;
The script only creates the numeric variable—you must also use the SET WEIGHT command to make it available as a weighting variable.
SET WEIGHT weight_cregion_gender;
When applied, the variables now reflect the targets:
If you want the sum of weights to equal the sample size (i.e., the weighted total N to match the unweighted total N), you can use the CREATE NUMERIC command to multiply the weight variable by a constant.