In last months worksheet we applied a pattern to validate or transform a quantity response during an interview. We will now look at applying a pattern at analysis stage. This particular example uses a derived variable in conjunction with a pattern to extract the postal area part from a full UK postcode.
This example uses the Snap WebHost edition of the Crocodile survey which is provided with Snap.
In this example, we will use a literal response, open ended question. This question has a source pattern of ‘Postcode UK’ applied. This pattern is pre-loaded within Snap and may be used to validate replies to literal response questions representing UK postcodes.
The UK postcode standard is made up of four components; Area, District, Sector and Unit. Each component is then broken down to accept a particular literal response as detailed in the table below:
|Component||Acceptable Literal Response||Example|
|B12 4LT BS35 3UW|
Step by step
The first step is to create a new pattern that will extract postcode area from a full UK postcode.
- Select Tailor | Patterns from the main Snap toolbar.
- Scroll down to the ‘Postcode UK’ pattern and highlight it.
- Click [Clone] to make a copy of it.
- Name the new pattern as UK Postal Area.
- Click in the Result box and clear the details. Right click, from the menu, select Component and then area, will then appear in the Result box.
- To test the pattern, click the button and type a postcode in the text box. If set up correctly, the result box should display just the area component of the postcode.
- Click to exit the pattern test and then click again to save your pattern.
The second step is to create a derived variable that can be used in conjunction with the UK Postal Area pattern that you have created above.
- Select the Variables icon from the main Snap toolbar.
- Click the icon to create a new variable. Make a note of the name and enter ‘Area’ as the Label
- The Type will be Derived and the Response will be Single.
- In the bottom half of the screen, double click in the Label column, and add a code label of Birmingham.
- Use the Tab key to move across to the Values column.
- Type Q11 as UK Postal Area ==”B”
Birmingham postcodes contain the letter B as the area component, e.g. B12 4LT. A value of Q11 as UK Postal Area =”B” will count any postal area containing B e.g. BS35 3UW which is a Bristol postcode. Therefore it is necessary to search for an exact match using = =.
- Tab again for the next code label which will be Bristol.
The value will be Q11 as UK Postal Area =”BS”
- Tab again for the next code label which will be Reading.
The value will be Q11 as UK Postal Area =”RG”
- To run the variable, click which will display the results in the Counts column.
- Click to save the derived variable.You can then use this new variable to create tables and charts.
If there is a topic you would like a worksheet on, email to firstname.lastname@example.org