Advanced tables and statistics > Weighting > Defining weights in a weighting matrix
 
Defining weights in a weighting matrix
Quick reference
To define a weighting matrix, type:
wmnumber axis_names[;weight_type][;maxwt=max][;minwt=min][;options];weight1;weight2;...
More information
There are two ways of defining characteristic weights:
set up a weight matrix that declares the weighting conditions and the weights to be applied
or
declare the weights in an ordinary axis and then label that axis as a weighting axis. This section explains how to declare weights in a weighting matrix.
Note Although you can write jobs that have weights declared in weighting matrices and in axes, the syntax for the two methods is not interchangeable. If you want to define weighting based on a combination of age and sex, say, you must either specify it all using a weighting matrix or all using an axis.
When you weight using matrices, each weighting matrix defines a set of conditions and the weights to be applied when a respondent is found having those characteristics. Matrix characteristics are specified in ordinary axes which might be used for other parts of the program, or not, as you choose. In the original example, if a respondent’s exact age is stored in c(107,108) and sex is a ‘1’ (Male) or ‘2’ (Female) in c106, the middle-aged women have c106’2’ and some arithmetic value between 45 and 54 in c(107,108). When these axes are used for weighting, base statements (n10, n11 and Base on col, val, fld, bit), text statements (such as n03), statistical rows (such as n12) and unweighted elements are ignored.
Weighting matrices are defined on wm statements in the following format:
wmn axis_names[;options];weights
where n is a unique number by which the matrix can be identified, axis_names are the axes defining the characteristics of this matrix, options are keywords defining the type of weighting required, and weights are the targets, factors or proportions to be used for weighting.
Note You cannot use a grid axis on a wm statement. If you need to define weights specifically for a grid axis, you should define a dummy axis with as many elements as there are cells in the grid axis and use that instead. For more information, see Weighted grids.
The matrix number can be any number between 1 and 9, and as long as no number is repeated, matrices can be numbered in any order.
Options for the wm statement
target
Targets (default).
factor
Factors.
input
Proportions.
rim
Rim weighting.
total=n
Cell values are to total to n.
pre=var
Preweighting using the value in variable var. This can be a data, integer, real or real-data variable. If the variable contains the value missing_, indicating missing data, the weight for the respondent is assumed to be zero.
post=var
Postweighting using the variable var. If the variable contains the value missing_, indicating missing data, the weight for the respondent is assumed to be zero.
maxwt=value
Maximum weight to be used in tables weighted with this matrix.
minwt=value
Minimum weight to be used in tables weighted with this matrix.
varname=name
Use this option when you are setting up a database for use with Quanvert to assign a name to the weighting matrix.
anlev=level_name
Use this option to cause weights to be applied only at the named level.
For more information about anlev=, see Defining weighting matrices in hierarchical data.
c=firstread
Use this option in trailer card data, to specify that weights are to be calculated only when the first card of a new record is read.
For more information about c=, see Defining weighting matrices in hierarchical data.
wmerrors/ nowmerrors
The wmerrors option is on by default. It causes the run to stop with an error if certain weight matrix errors are detected. Use nowmerrors to switch the option off, so that the run continues with a warning. For more information about wmerrors and nowmerrors, see Weight matrix errors.
Combinations that are not allowed
The following combinations of options are not allowed on wm statements:
any combination of target, factor or rim
input with total.
Note Quantum does not prevent you from putting both input and total on the same weight matrix. However if you do this, without giving a warning Quantum ignores the one you specified first and uses the other one. For example, Quantum interprets:
wm1 sex;input;total=1000;60;40
    as     wm1 sex;total=1000;60;40
wm1 sex;total=1000;input;60;40
    as     wm1 sex;input;60;40
For example, you might have a matrix defining weights for age and sex. The matrix consists of targets based on population figures for the area covered by the survey:
   Population of Surveyed Area
                    Sex
Age            Male      Female

18-24          6,200      6,100
25-34          7,600      7,500
35-44          8,200      8,300
45-54          9,600     10,000
55-64          7,100      7,600
65 and Over    4,600      5,900
so you write:
wm1 age sex;target;6200;6100;7600;7500; ... 4600;5900
You can enter the weights on separate lines, as the figures are to be printed in the table:
wm1 age sex;target;
+6200;6100;
+7600;7500;
     .
+4600;5900
In this example, all the weights are whole numbers, but Quantum can cope equally well with weights which are real numbers.
If several consecutive weights are the same, you can write the weight out once and precede it by an asterisk and the number of times it is to be repeated. For example:
3*10.5
indicates that three consecutive cells have a weight of 10.5.
If the tables are to be correct, you must enter the axis names and the weights in the correct order. Axes are entered as they are for tab statements; that is, higher dimension axes followed by column axis followed by row axis.
Weights are entered on a row by row basis, working from left to right along the row. As you can see by comparing the numbers on the wm statement with those in the chart above, the first two numbers are the weights for men aged 18 to 24 and women aged 18 to 24, in that order. There is no need to keep weights for different characteristics on different lines; just string them one after the other separated by semicolons on the same line. If you run out of room, continue on the next line remembering to start the line with a plus sign to tell Quantum it is a continuation.
Suppose that the chart looked like this:
              Population of Surveyed Area

                            Age
          18-24  25-34  35-44  45-54  55-54    65+

Male      6,200  7,600  8,200  9,600  7,100  4,600
Female    6,100  7,500  8,300 10,000  7,600  5,900
The wm statement would then be written as:
wm1 sex age;target;6200;7600;8200; ... 7600;5900
You can think of weighting as creating a table in which you specify the axes to create the cell-conditions, and also define the numbers to go into those cells. When a table is created that uses these weights, Quantum first checks which cell of the table the respondent belongs in, then it looks to see which cell of the weighting matrix refers to them. Finally, it reads the appropriate weight from the matrix and increments the cell count in the table by this value instead of by 1.0.
To use both preweights and targets, write:
wm4 work age sex;pre=c(181,189);target;1200;2400;1400; ...
The preweight read from c(181,189) is applied before the targets listed on the wm statement.
See
Weight matrix errors
Defining weighting matrices in hierarchical data
Multidimensional weight matrices
See also
Weighting