Advanced tables and statistics > Dealing with hierarchical data > Analysis levels > Defining levels and the data structure using a struct statement
 
Defining levels and the data structure using a struct statement
Quick reference
To name levels and define the structure of a levels database, type:
struct; read=2; ser=c(m,n); crd=c(m,n);
+lev=level_name[<parent_level][,card_numbers][; maxsub=number]
More information
As an alternative to the levels file, you can define the structure of a levels data file using a struct statement with additional options that name the levels and define their relationships to each other.
On the struct statement, specify read=2, and use ser= and crd= to define the serial number and card type columns as you would for an ordinary data file. If records have more than nine cards you will also need to use max= to increase the size of the C array so that it has room to store the data for cards 10 and above.
Use lev= to name the levels and define their relationships:
lev = level_name[<parent_level][, card_numbers]
where:
level_name is the name of the level you are defining.
parent_level is the name of the level to which the current level belongs: it must be one which has already been declared.
card_numbers are the cards on which the data for level_name is held. If the data is on the same card(s) as the parent level you can omit the card reference. You can specify ranges of card numbers either by typing the individual numbers as a comma-separated list, or by using one of the range specifications start/end or start:end. If some cards must be present in every record, follow the card number with the letter ‘r’. If all cards in a range are mandatory and you have used a / or : range specification, you can type ‘r’ once at the end of the range.
You will need one lev= option for each level.
Examples
struct;read=2;ser=c(1,4);crd=c5;
+lev=hhold,1r; lev=person<hhold,2r,3
This example declares a data file with two levels. The top level is household which is held on card 1. Every record must have a card 1. The second level is person. This is a sub-level of household and the data is held on a mandatory card 2 and an optional card 3.
struct;read=2;ser=c(1,4);crd=c5;
+lev=person,1r; lev=trip<person,2; lev=shop<trip
The data file for this example has three levels. Person is the top level and is held on a mandatory card 1. Trip is the second level and, if it is present, is held on a card 2. The third level is shop which, since it has no card specification of its own, is assumed to be held on card 2.
struct;read=2;ser=c(1,4);crd=c5;
+lev=doctor,1:3r; lev=patient<doctor,4r,5
This example has two levels. Information about the doctor is held on cards 1, 2 and 3, all of which must be present for each record. Information about the doctors’ patients is held on cards 4 and 5. Card 4 is mandatory and card 5 is optional.
To define the maximum number of sub-levels a record can have, use the maxsub= option:
maxsub=number
For more information about sub-levels and maxsub=, see Defining the data structure in the levels file.
See also
Analysis levels