Advanced tables and statistics > Dealing with hierarchical data > Analysis levels > Table creation level
 
Table creation level
Quick reference
To create a table at a higher level than that of its axes, type:
celllev=level_name
on the tab statement.
More information
A table can be created at a higher level than the axes by using celllev= on the tab statement. For example, to produce a table of age by sex which shows, not the number of men between 20 and 30 years of age, but the number of households having men in that age group, write:
tab age sex;anlev=person;celllev=hhold
l age;anlev=person
val c(213,214);Base;i;Under 18=0-17;18-25;26-35;36-45;
+46-55;56-65;66+
l sex;anlev=person
col 210;Base;Male;Female
Both axes are created on a person-by-person basis since each person’s data has to be read to obtain their age and sex. Because both axes have an analysis level of person, the tab statement which cross-tabulates them must also be at that level. Normally this produces a count of people, but to get a count of households, use celllev to specify the household level. This causes Quantum to increment each cell in the table only once per household, regardless of the number of people in each cell.
Note celllev= is only valid on tab statements.
The table base is only updated for records that have data at the level defined with celllev; that is, the level at which the cell counts are made. For example, if level 1 is household and level 2 is child, tables created with anlev=child;celllev=hhold only include households with children because the axes on which the cell counts are based are at child level. If you compare this table’s base cell with a table created entirely at household level you should not expect the two table bases to be the same unless every household in the data file has at least one child.
To illustrate this, consider the following basic spec:
tab htype region;anlev=hhold
tab age sex;anlev=child;celllev=hhold
l region;anlev=hhold
col 116;Base;North;South;East;West
l htype;anlev=hhold
col 118;Base;Detached house;Terraced house;Bungalow;Flat
l age;anlev=child
val c(213,214);Base;i;Under 5=0-4;5 to 11;12 to 15;16 to 18
l sex;anlev=child
col 210;Base;Male;Female
The first table shows the number of households by type of house and region. The table base is the total number of households in the data file. The second table uses data at child level and the table base only includes households with children.
However, sometimes you might want the base in the second table to include all households regardless of whether or not they have children. To achieve this, you must use uplev= and levbase, as described in uplev and levbase.
See also
Analysis levels