Você está na página 1de 171

Tables and Reporting

Ipsos IBM SPSS Data Collection Training

Author(s): Cosmin Bucuroiu, Sergiu Popa, Oana Mihai 1st August 2017
v3
Course Contents

Summary

Dimensions - a general guide


Viewing data in DMQuerry
My first tables
Axis expression
Statistical elements
Applying Filters to Tables
Creating Grid Tables
Data Management Scripts
My first data transformation script
Special tables
Weighting
Open Ends
Merging data sets
Extra

2 2 2011 Ipsos
Dimensions Overview
Data Collection Concept

The Data Collection (aka Dimensions) products aim to...

Simplify the Market Research data collection and analysis


process.
Bring all the interviewing modes under the same scripting
language.
Create efficiencies in a complete end-to-end process.
Allow smoother transition between different data formats using
the Data Collection Data Model.

4 2011 Ipsos
Data Collection Data Model : File Types

There are two principle types of file that Dimensions can read &
write.

1. Metadata (MDD)
Contains a description of the data file
All question & code text

2. Case Data (DDF)


Respondent data

5 2011 Ipsos
Metadata

Metadata is one of the most important Dimensions files and can include:

Question and category labels and other texts available to interviewers


and respondents.

Variations of texts for use in different contexts. For example, question


texts for interviewing and shorter texts for analysis.

Translations of texts for multicountry studies.

Layout information for the way questions are grouped, for example,
loops and grids.

Presentation information, such as the way questions are laid out on the
screen or on the page, and how texts are formatted.

6 2011 Ipsos
Metadata

When used for Interview Scripting it also includes the Script Routing. This is
the logic that controls

When and how questions are asked.


How questions and responses are presented.
Who sees which questions.

Having metadata separate from case data improves the workflow because you
can perform operations on the metadata, such as translating and editing,
independently of case data.

7 2011 Ipsos
Case Data

This is the actual respondent data recorded for an interview.

The rows represent a case/respondent and each column represents a


variable

Case Data cannot be interpreted by the Data Model without a


corresponding Metadata file.

8 2011 Ipsos
Data Collection Data Model : Overview

Quancept
QDI + DRS Quanvert
Quancept
PKD
+ Quantum
(read only)
QDI + DAT (read only)

DSC
DSC DSC

Triple-S DATA
XML +
DSC
MODEL
ASCII

DSC
DSC DIMENSIONS
Metadata (MDD)
Case Data (DDF)
SPSS
Database Statistics

SAV

9 9
2011 Ipsos
Dimensions Scripting

There are three main types of Dimensions scripts:

Interview Scripts (.mdd)

Data Management Scripts (.dms)


These are used for performing data management tasks, such as cleaning
and transferring data, creating derived variables for use during analysis,
and setting up weighting schemes.

mrScriptBasic (.mrs) Files


Typically used for creating tables, toplines, reports and charts.

10 2011 Ipsos
Programming Languages

There are two main languages for all programming roles:

mrScriptMetadata (all variables and text elements are


defined here)
Used in MDD and DMS files (in the Metadata)

mrScriptBasic object-oriented language, similar to Visual


Basic, uses object types:
IOM used in MDD routing
DMOM used in DMS
TOM used in MRS

11 2011 Ipsos
Dimensions Workflow

Dimensions works at its best when used throughout the survey


process, or end-to-end.

There are four main stages in the Dimensions workflow:

Data Reporting and


Scripting Interviewing
Management Analysis

12 2011 Ipsos
Scripting

Data Reporting and


Scripting Interviewing
Management Analysis

Locally processed
Script written in Base Professional
Tested offline on the Scriptwriter's PC.
Define Quotas
Add Translated Texts
Upload files to server using Activation Console

13 2011 Ipsos
Interviewing

Data Reporting and


Scripting Interviewing
Management Analysis

Server-based
Testing projects
Live interviews
Survey Management
Progress reports
User management
Sample

14 2011 Ipsos
Data Management

Data Reporting and


Scripting Interviewing
Management Analysis

Locally processed
Download data from server
Merge data files
Recoding
Weighting
Add custom variables
Export data

15 2011 Ipsos
Data Management

Data Reporting and


Scripting Interviewing
Management Analysis

Locally processed
Tables
Reports
Client deliverables
Survey Reporter - Web

16 2011 Ipsos
Software Tools

Data Management & Analysis

Base Professional
Interviewer Server used by SW
DMQuery
Survey Reporter
Web sharing data/tables
Desktop Checking and building tables specs
Workbench Desktop
Artifact Data Table Visualisation

17 2011 Ipsos
Metadata

Data Collection uses the Metadata Model (MDM) to read and


write Metadata and is programmed in the mrScriptMetadata
language.

Metadata files have the .mdd suffix.

The minimum content of an MDD file would contain only the


Metadata to describe contents of the case data file.

A MDD Metadata file is created for all exports of all data


formats to help smooth process of read/writing other formats.

18 2011 Ipsos
Basic Metadata Item Structure
Metadata items are used to define information texts, questions and sets of
possible responses for an interview.

All item types follow a standard structure:

item_name "Item Label" variable_type [range_expression] other_options;

Depending on the item type, range expressions can be specified to apply a


limit on the responses that can be recorded.
Such as minimum/maximum values or a min/max number of responses.

Additional commands and options can be added to the item before the semi-
colon to enhance functionality and add additional items.
We will look into these later in the course.

Metadata code is color-coded by Base Professional as:


Text , Keywords , normal code and syntax
19 2011 Ipsos
Metadata Item Naming
Metadata items are generally referenced by their name at all processes
throughout the entire Dimensions workflow. Giving these items meaningful and
clear names is therefore beneficial in speed and re-usability.

mrScriptMetadata names...

Can contain letters, numbers and underscore "_" characters.


Must start with letters A to Z or an underscore (e.g. Q1, _1)
Are not case sensitive.
Must be a whole word or string of characters:
INCORRECT: My Question
CORRECT: MyQuestion or My_Question
Cannot be a word used as a command or keyword by mrScriptBasic or SQL,
e.g.: If, For, Select, Next, Case, Name, AnswerCount etc.

20 2011 Ipsos
Metadata Item Types

These are the available item types we can specify in the Metadata section:

info Displays text on the screen. No data is recorded.

long Requires a whole number response.

double Requires a numeric response that can contain decimals.

text Requires a text response.

Requires the respondent to select one or more answers from a


categorical
predefined list of responses (covered in the next chapter).

boolean Requires a True or false value as the response.

date Requires a date and/or time to be entered.

21 2011 Ipsos
Special Characters
mrScriptMetadata uses special characters to help layout and separate aspects of
your script. You will become more familiar with these special characters with
practice.
Symbol Name Description
{} Curly brackets Items in brackets define list items
Items in square brackets typically define values and are
[] Square brackets sometimes optional

() Curved brackets Used to hold parameters


, Comma Use to separate items in a list
Denotes the end of a statement when defining
; Semicolon questions and responses

_ Underscore May be used to separate text in a single word field

Using two double quotes within an item's label text will


Two double display as one double quote on screen.
""
quotation marks e.g. "John said ""Hello!""" would display as: John said
"Hello!"

22 2011 Ipsos
Range Expressions

As we look at each item type in more detail in the following lessons, we will
look at the use of range expressions.

These allow us to get more control over what values can be entered.

They can be applied to all item types except info and boolean.

Range expressions are optional. If one is not specified, the question will be
validated according to the system defaults.

A range expression is defined between square brackets after the item type.
This example will only allow any whole number between 18 and 99 to be
entered.
Age "How old are you?" long [18..99];

23 2011 Ipsos
mrScriptMetadata: Variable Types (1/6)

1. Text
Q4 "What do you think about Coca Cola zero?" text [..100];

2. Numeric long/double
Q2 "What is your age?" long[0..100];

3. Categorical
Q1 "What is your gender?" categorical [1..1]
{
_1 "Male",
_2 "Female"
};

24 2011 Ipsos
mrScriptMetadata: Variable Types (2/6)

4. Loop/Grid
Q8 "How would you rate the following movies?" loop
{
_1 "Silence of the lambs",
_2 "South park - Bigger, longer and uncut",
_3 "Iron Man 3"
} fields -
(
Q8_scale ""
categorical [1..1]
{
_1 "Great",
_2 Mediocre",
_3 "Horrible",
_4 "Haven't seen it" NA
};

Q8_text "Your thoughts on it."


text [..255];

) expand;

25 2011 Ipsos
mrScriptMetadata: Variable Types (3/6)

5. Block Qblock "" block


fields
(
Q9 "What did you like about this survey?"
text;

Q10 "What did you dislike about this survey"


text;

);

QCompound "Compound label" compound


6. Compound {
use myList -
} fields
(
Q11 "Which is the slowest browser?"
categorical [1..1];
Q12 "What is your opinion on each of these browsers?" loop
{
} fields -
(
Q12_scale ""
text;

);
);

26 2011 Ipsos
mrScriptMetadata: Variable Types (4/6)

7. Info
An information item displays text on the screen.
You use information items to display text that is not related to
the questions such as section titles, instructions to
respondents, or instructions to interviewers.
No data is recorded & range expressions cannot be used.

27 2011 Ipsos
mrScriptMetadata: Variable Types (5/6)

8. Boolean (True/False) Responses


During interview only a checkbox is displayed. If it is checked
then the value will be true. If left unchecked the value will be
false.
If the question was not asked the value will be null.

Agree "If you buy another product from Widgets Inc in the future, would
you be willing to do another Satisfaction Survey for Widgets Inc? Tick the
box if you are willing to participate." boolean;

28 2011 Ipsos
mrScriptMetadata: Variable Types (6/6)

9. Date and Time


These variables store date and time information.
Dates can be written using:
Letters or numbers for the month.
Years can be entered using two or four digits.
"/" or "" as the separator between days, months and years.
Times may be specified in 12-hour format as hh:mmam or hh:mmpm, or in 24-hour
format as hh:mm.

Dob "Please enter your date of birth"


date ["1-Jan-1906".."31-Dec-2006"];

TimeBooked "What time was your table booked for?"


date ["12:00pm","2:00pm","06:00pm".."11:00pm"];

ConsultantTime "When was your appointment with the research consultant?"


date ["2-Jan-07 09:00am".."31-Jan-07 05:00pm"];

29 2011 Ipsos
Categorical Question Syntax
Categorical is the general term for a single-choice or multiple-choice response.
When you define a categorical question, you define the responses from which
choices may be made, and the number of choices that will be allowed.
Response categories are encased in curly brackets, and are defined using the
same syntax as the question and are separated by commas.
A response text is optional. If no text is defined it will use the label, so if your
label is the same as the text there is no need to repeat it.
The semi-colon ";" that ends the question variable appears after the closing
curly bracket "}".

QuestionName "QuestionText" categorical [Range_Expression]


{
CategoryName1 "Category label 1",
CategoryName2 "Category label 2"
};

30 2011 Ipsos
Range Expression for Categorical Questions
The range expression for categorical questions has a number of possible
variations which define the restrictions on number of responses a respondent can
give.

Use this to define a single-answer question.


[1..1] Minimum and maximum of one response is required.
Use this to define a typical multiple-answer question.
[1..] The respondent must provide a minimum of one answer with no maximum limit.
[2..5] The respondent must provide a minimum of two and a maximum of four answers.
The respondent can leave the question blank with no maximum limit on the number
[..] of responses. Information only DO NOT USE.
[..3] The respondent can leave the question blank or provide a maximum of three
answers. Information only DO NOT USE.

31 2011 Ipsos
Range Expression for Categorical Questions
Always specify a minimum of 1 response.
If we do not specify a minimum response we allow the respondent to avoid
answering the question.

Do not specify a maximum for normal multi-answer questions.


When a maximum is not specified the maximum is automatically defined as the
total number of categories available.
This allows for more categories to be added in the future without needing to
adjust the range expression.

Only specify a maximum for:


Single response questions
Multiple response questions that require a fixed maximum number of answers.

Examples
Q1 "Single response" categorical[1..1]
Q2 "Multiple responses" categorical[1..]
Q3 "A minimum of 2 and a maximum of 5 responses" categorical[2..5]

32 2011 Ipsos
Special Keywords on Categories

Special keywords can be added to a category that come into effect during
interviewing.
For now, we will look at exclusive, fix and nofilter keywords.

33 2011 Ipsos
Single-Choice Responses in Multiple Response Lists
Here is an example of using exclusive. If selected, the None category must be the
only answer for the question.
Heard "Where do you recall seeing or hearing advertisements for Widgets Inc in the past
year?" categorical [1..]
{
Television,
Radio,
Newspapers,
Magazines,
Internet,
None "I dont recall seeing or hearing any advert for Widgets Inc" exclusive
};

34 2011 Ipsos
Subheadings
We can group categories together by using sub-headings.
Response categories are grouped by defining a sub-heading name, sub-
heading label/text (optional) and enclosing the responses using curly brackets.
Unlike the question structure the closing curly bracket for a subheading should
NOT be followed by the semi-colon.
Each sub-headed group should be separated by a comma.

Qname "Text" categorical[Range_Expression]


{
Subhead_name1 "Subhead_text1"
{
Responses
},
...
Subhead_namen "Subhead_textn"
{
Responses
}
};

35 2011 Ipsos
Shared Category Lists (Define Lists)
Response categories can be shared across questions by defining them as a
shared list. We do this by creating a list of categories using the define keyword.

attributes "" define


{
Colour "Colour",
Weight "Weight",
Size "Size",
Texture "Texture",
Quality "Quality of manufacture"
};

Shared lists are automatically put to the beginning of the metadata section
when you re-open your .MDD file in Base Professional, unless they have been
defined in blocks where they will appear at the beginning of the block.
Normally, you would not add a text label to the define list unless you are using
it as a sublist and need to define the sublist's heading.

36 2011 Ipsos
Shared Category Lists : Standard Questions

To reference the list in a question add the use keyword followed by the
name of the list where you would normally define your categories.

Like "What aspects did you LIKE about the last product you bought?"
categorical [1..]
{
use attributes -
};

Dislike "What aspects did you DISLIKE about the last product you bought?"
categorical [1..]
{
use attributes -
};

37 2011 Ipsos
Shared Category Lists : Standard Questions

When referencing more than one category list at a question, use lines must
still be separated by a comma as if it were a normal response option.
In this example, two category lists are combined into one single list during
the interview.

Heard "Where do you recall seeing or hearing advertisements for Widgets Inc in
the past year?"
categorical [1..]
{
use newspapers,
use magazines
};

38 2011 Ipsos
Shared Category Lists: Grids and Loops

Shared category lists can also be used to define loop categories as well as
lists for questions inside loops.

LikeDislike_Loop loop {
use Brand_list
} fields (
Like "What aspects did you LIKE about {@}?" categorical [1..]
{
use attributes -
};

Dislike "What aspects did you DISLIKE about {@}?" categorical [1..]
{
use attributes -
};
) expand;

39 2011 Ipsos
Special Responses Categories

Special response categories have a dedicated function in the questionnaire which


in some cases can apply the properties of keywords such as fix or exclusive
without having to manually add them in.

Dont Know
dk
exclusive, fix and nofilter keywords are applied automatically.

Refused
ref
exclusive, fix and nofilter keywords are applied automatically.

No Answer
na
exclusive, fix and nofilter keywords are applied automatically.

Other (specify)
Adds a text box next to the category code.
other If text is entered, the category check box must be clicked.
Unlike dk, ref and na, the exclusive, fix and nofilter keywords must be
added to suit the demands of the survey.

40 2011 Ipsos
Special Responses in a Categorical Question
Here is an example of the special categories in use:

Items "What items did you purchase from Widgets, Inc. the LAST time you placed an
order?" categorical [1..] {
Jumbo,
Large,
Medium,
Small,
OtherItem "Other Item(s) - please separate items with commas" other,
- "Dont recall" dk,
- "Refused" ref,
- "No Answer" na
};

41 2011 Ipsos
Other (Specify)
Adding the other keyword opens up a text box for respondents to add their own responses.

OtherItem "Other Item(s)" other

You can further modify the inherent properties of the other category:

OtherItem "Other Item(s)" other (OtherItems "" Text [1..100])

You can modify the data type and further modifications specific to that data type. In the
above example we have specified that the text is stored in a variable called OtherItems and
restricted it to 100 characters.

Example:
Q6 Select brands purchased in the past 6 months categorical[1..]
{
Use Brandlist,
_997 Other (please specify) other(oth My Text text[1..100])
};
42 2011 Ipsos
Adding Special Responses to Text or Long Questions

It is also possible to add special category codes onto text or numeric questions.
Categories can be added to the variable in the codes section.
Inside the codes section, all categories are specified between curly brackets {
as usual.

NumTimes "On average, how many times per year do you order something from
Widgets Inc.?" long [0..20]
codes (
{
- "I cannot remember" dk
}
);

43 2011 Ipsos
Sorting & Ordering Categorical Responses
These are keywords that manage the orientation of categorical response lists.

rotate / rot Rotate list by one category before each presentation

randomize / ran Present list in a randomized order

Reverse the list before each presentation.


reverse / rev This means that the list is presented top-down to the first respondent,
bottom-up to the next, etc.

ascending / asc Sort in ascending alphabetical order

descending / desc Sort in descending alphabetical order

WhereUse "Where have you been using your Widgets Inc product since you purchased it?"
categorical [1..]
{
Home "Inside your Home",
Garden "In your Garden",
Work "At Work",
NotUsed "I've not been using it since I purchase it" exclusive
} ran;

44 2011 Ipsos
mrScriptBasic: Statements (1/3)

1. Assignment Statements

variable = expression

Set objectvar = objectexpression

The Set keyword, which is required in VBScript for assigning objects,


is also required in mrScriptBasic for assigning objects. The Set
keyword makes it possible to distinguish between object assignment
and default property value assignment.

45 2011 Ipsos
mrScriptBasic: Statements (2/3)

2. Conditional Statements
1. If Then Else
If expression Then
[statements]
[ElseIf expression-n Then
[elseifstatements]]
...
[Else
[elsestatements]]
End If

2. Select Case
Select Case testexpression
[Case expression-n
[statements-n]]
...
[Case Else
[elsestatements]]
End Select

46 2011 Ipsos
mrScriptBasic: Statements (3/3)

3. Iteration Statements
1. For Next
For counter = start To end [Step step] [{Ran|Rot|Rev} [it]]
[statements]
[Exit For]
[statements]
Next

2. For each
For Each element In group
[statements]
[Exit For]
[statements]
Next

For more information on Statements, visit


http://pic.dhe.ibm.com/infocenter/spssdc/v6r0m1/topic/com.spss
.professional/mrscriptbasic_langref_statements.htm

47 2011 Ipsos
mrScriptBasic: Variables

NB: Not to be confused with mrScritptMetadata variables

Dim MaxRating, MinRating

A variable may be accessed or modified by any code after the


line on which the variable is declared.
Dim MaxRating, SomeString, MinRating

MaxRating = 100

SomeString = This is some string

[statements]

MinRating = MaxRating/2

MaxRating = 50

48 2011 Ipsos
mrScriptBasic: Variables - Arrays

Declaration
'An array of 10 elements
dim A[10]
'An array of dynamic dimension
dim A[]

You assign data to each of the elements of the array using an index into the
array. Indexes are 0 based in mrScriptBasic. Maximum array index for A[10]
is therefore 9.
A[0] = 256
A[1] = 324
A[2] = 100
...
A[9] = 55

Arrays can contain numbers as well as strings

Dim MyArray[2]
MyArray[0] = "Hello"
MyArray[1] = " World"

49 2011 Ipsos
mrScriptBasic: Variables - Arrays

If you specify the number of elements when you define an


array, the array cannot increase in size. If you refer to or assign
a value to an element outside of the range that you have
defined, an error is generated. Likewise for negative or non-
integer indexes.
'An array of 10 elements
dim A[10]
'The following would throw errors
A[10] = 256
A[-1] = 324
A[0.5] = 100

You cannot assign an array to another array. Use iteration


statements instead.
'An array of 10 elements
dim A[],B[]
'The following would throw errors
A=B

50 2011 Ipsos
mrScriptBasic: Variables - Arrays

You may create multi dimensional arrays. Only the last


dimension can be dynamic.
' 10 rows, dynamic columns
Dim TempTable[10][]
5 x 10 x 15
Dim array3D[5][10][15]

The following are invalid definitions:


Dim dummyA1[][10]
Dim dummyA2[3][][]

Limitations:
You can only have as many as 60 dimensions in an array.
The maximum number of items in any one dimension of an array
is 65536.

51 2011 Ipsos
mrScriptBasic: Conversion Functions

May be used to convert a variable from one type to another.


Function Description
Converts a value of any data
CBoolean
type to a Boolean value.
Converts a value of any data
Ccategorical
type to a Categorical value.
Converts a value of any data
Cdate
type to a Date value.
Converts a value of any data
Cdouble
type to a Double value.
Converts a value of any data
CLong
type to a Long value.
Converts a value of any data
CText
type to a Text value.

52 2011 Ipsos
DM Query

DMQuery is a useful tool for viewing data.


Opens any format of data supported by the Data Model.
Uses SQL commands to view and edit the data.

DMQuery is stored in the DDL directory:


[installation directory]\DDL\Code\Tools\VB.NET\DM Query\DMQuery.exe

53 2011 Ipsos
Running Queries in DM Query (1/4)

Double-click the DM Query.exe file. This opens the DM Query


window and the Connection tab in the Data Link Properties
dialog box.

54 2011 Ipsos
Running Queries in DM Query (2/4)

Have a look at the Metadata Type dropdown list.


This shows all the metadata files supported by the Data Model.

For the Metadata Type you can leave as the default "Data Collection
Metadata Document".
This is the MDD file.
Browse to the location of your MDD & DDF files and select the MDD file.

From the Case Data Type drop-down list, select Data Collection Data File
(read-write).

Enter the Case Data Location using Browse if the DDF file has not been
found automatically.
Leave the Case Data Project text box blank.

55 2011 Ipsos
Running Queries in DM Query (3/4)
Click the Advanced tab, and from the Categorical Variables drop-down
list, select Return data as category names.

This is essential for viewing categories in the


data.
If you do not do this, any answers to categorical
questions will appear under their database IDs
which are almost impossible to understand
with ease.

Click OK.
This returns you to the DM Query window.

56 2011 Ipsos
Running Queries in DM Query (4/4)
To view the data we need to enter an
SQL Query.
Enter this query to view all variables
in the VDATA table

SELECT * FROM vdata

The SQL Query below will show only


the requested variables.

SELECT age, gender FROM vdata

57 2011 Ipsos
SQL Queries
View data for all variables in VDATA.
SELECT * FROM vdata Same can be used for hierarchical data by referencing HDATA instead.

SELECT serial, age, gender FROM vdata Show data for serial, age and gender variables.

SELECT serial, age, gender, visits FROM vdata


Show data for the specified variables in order of responses for age.
ORDER BY age
SELECT * FROM vdata ORDER BY serial DESC Show data for all variables in descending order of serial number.

SELECT DISTINCT gender, before FROM vdata Uses the DISTINCT command to deduplicate the results shown

SELECT serial, age, gender, visits FROM vdata


Show data for the specified variables for all male respondents .
WHERE gender = {male}
SELECT serial, age, gender, visits FROM vdata Show data for the specified variables for respondents who have made a
WHERE visits > 0 visit.
Show name and address data for respondents whose address contains the
SELECT name, address FROM vdata
string "London_W", where "_" matches any character and "%" represents
WHERE address LIKE '%London_W%' aby number of characters before or after the string.
SELECT serial, age, (visits + visits12) Show the results of adding two varibles together filtered on either variable
FROM vdata WHERE visits > 0 or visits12 > 0 having a value of more than zero.

SELECT serial, museums FROM vdata


List the data where the answers of museum question are not null.
WHERE museums IS NOT NULL ORDER BY serial
SELECT serial, remember FROM vdata Uses the "containsall" function to filter on multiple categories. Could also
WHEREremember.ContainsAll({Botany,Minerals}) use "containsany"

58 2011 Ipsos
Creating a Basic Table
Lesson 1
Creating a Basic Table

Lesson Objectives

The Tables Object Model (TOM)


How to create and execute a Script
The basic structure of a Script
Script Assist and Function Signatures
Changing Labels for Tables
Nesting and Concatenating Variables
Tabulating an open variable

60 60 2011 Ipsos
Create Your Initial Script

File menu > New... File

61 61 2011 Ipsos
Decomposing the Script

Dim objTableDoc

the Dim statement reserves space in the computer


memory for a variable
In this case the variable is called ObjTableDoc

62 62 2011 Ipsos
Decomposing the Script

Set objTableDoc = CreateObject("TOM.Document")

the Set command allows us to determine that the variable


ObjTableDoc will take the value of an object, rather than
any other value
you have asked your computer to create a new object of the
Tables Object Model Document in the memory space called
ObjTableDoc

63 2011 Ipsos
Decomposing the Script

objTableDoc.DataSet.Load(Day 1.mdd",,_
Day 1.ddf","mrDataFileDsc")

this block of code determines which data will be used in order


to generate the table of results
the code between the parentheses supplies 3 pieces of
information:
the metadata file (Day 1.mdd)
name and path of the case data file (Day 1.ddf)
name of the specific DSC (mrDataFileDsc) which is to be used to read
the case data

64 2011 Ipsos
Decomposing the Script

Dim objTable
Set objTable = objTableDoc.Tables.AddNew(Table1, Q1* Q2, My
First Table)

the code creates a table, called ObjTable, which will be a


system object
this specific object is created by using the Tables object
within the ObjTableDoc object
within the Tables object we want to use a method with 4
parameters called AddNew(P1,P2,P3,P4), the 4th being optional

65 2011 Ipsos
Decomposing the Script

The information within the parentheses of the AddNew


Method determine the contents of the table
P1 is the name of the table that will be displayed in the output
(cannot contain spaces or punctuation marks)
P2 specifies the variables that are to be displayed on each axis of
the table (prior to the asterisk (rows), after the asterisk (columns))
P3 declares the description of the table and allows you to give a
more user friendly description of what this particular table is
showing
P4 is an index parameter which allows a user to specify a specific
table by using its index number

66 2011 Ipsos
Decomposing the Script

objTableDoc.Populate()

this code is saying Use the populate method of the


Tables Document Object to fill the contents of the table
so this is the place where the table generation happens

67 2011 Ipsos
Decomposing the Script

objTableDoc.Save(Day 2.mtd)

saves the table to an XML file called Day 2.mtd


this file can be opened within the mrTables module or
viewed in XML format
can be opened into Survey Reporter

68 2011 Ipsos
Decomposing the Script

With TableDoc.Exports[mrHtmlExport]
.Properties[Interactive] = True
.Properties[LaunchApplication] = True
.Properties[DisplayOption] = Table Only
.Export(Day 2.htm)
End With

we are declaring that we wish to export the table to HTML


format so that it can be viewed in a web browser
the table should be interactive

69 2011 Ipsos
Basic Code Structure Used in Exporting Tables

To get a useful export facility in a practical sense (e.g. HTML)

With TableDoc.Exports[mrHtmlExport]
.Properties[DisplayOption] = Table Only
.Properties[LaunchApplication] =True
.Properties[Interactive] = True
.Export(Day 2.htm)
End With

the property in line 3 physically launches an instance of the


application to which you are exporting
line 2 will generate a prompt asking if it is acceptable to
overwrite the existing export file (if a copy of the export file
already exists)

70 2011 Ipsos
Basic Code Structure Used in Exporting Tables

the OverwriteOutput property as alternative to


Interactive

.Properties[OverwriteOutput] = True

In this case the output will be automatically overwritten if


the same file name is used twice
We should use this by default

71 2011 Ipsos
Change Tables/Categories Labels

Two ways for changing labels variables within tables:


ANALYSIS
Directly from tables script

Variable Label
objTableDoc.DataSet.MdmDocument.Fields[Q1"].Label="Gender"

Category Label
objTableDoc.DataSet.MdmDocument.Fields[Q1"].Categories[{_1}].Label =
MALE"

Best Practice
Dim MDM
MDM=objTableDoc.DataSet.MdmDocument.Fields
MDM["ISQ20"].Label="Gender

72 2011 Ipsos
Nesting and Concatenating Variables

When multiple variables are inserted within a table axis then


they must be either nested or concatenated
Syntax to determine how variables are treated:

+ The variables (called axes) are to be concatenated. Display


order is from left-to-right.
> The variable (axis) on the right of the > symbol is to be
nested within the axes on the left of the symbol
() Parentheses are used to indicate that the symbols within
are to be evaluated before the symbols outside the
parentheses

Generally the evaluation takes place from left to right and the
> symbol takes precedence over the +

73 2011 Ipsos
Concatenating Variables

Concatenation means appending multiple variables on


the same axis
You can concatenate in both table axes

Set objTable = objTableDoc.Tables.AddNew(Table1, Q1+ Q3* Q5+ Q6,


Concat Table)

74 2011 Ipsos
Nesting Variables

A nested table is created when one variable is layered


within another variable
You can nest in both table axes

Set objTable = objTableDoc.Tables.AddNew(Table1, Q1> Q3* Q5> Q6,


Nested Table)

75 2011 Ipsos
Ordered Nesting and Concatenation

It is possible to combine Nesting and Concatenation


within the same table

This is a way that banners should be built

Examples:
Q1> Q3+ Q5
Q5+ Q6> Q1

76 2011 Ipsos
Axis expression
Lesson 2
Creating Nets

Overview

Expanding categorical variables


Include/Exclude base element
Add total to tables
Creating Nets
Sorting tables

78 2011 Ipsos
Variable Presentation Axis Expression using {}

"DrinkAlcohol{Yes, No, Ref}"

The axis expression is applied immediately after the variable is


used in the table specification

It is defined between curly brackets { }

In this case all the categories are included, {Yes, No, Ref}

The category names are from the mdd, open and use this as
reference

The same could be achieved with {..} , the double dots


indicate to treat the rest as per the mdd

79 2011 Ipsos
Expanding categoricals

In order to be able to create nets or statistical elements , the


variable inside the table definition must be expanded
You can expand in both table axes

Example:

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{_1,_2} *


Q2{_1,_2,_3,_4}","Cross Age by Gender")

same thing as

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{..}*Q2{..}","Cross


Age by Gender")

80 2011 Ipsos
Excluding categories from tables

Expanded variables gives the opportunity to specify the categories needed


in the tables
Examples:
Excluding categories _2,_4,_6 from table

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{_1,_3,_5,_7}*Q2","Cross Age


by Gender")

Excluding category _7 from table

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{.._6}*Q2","Cross Age by


Gender")

Excluding category _3 and _4 from table

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{.._2,_5..}*Q2","Cross Age by


Gender")

81 2011 Ipsos
Hidding Categories [IsHidden=true]

You can leave out categories you dont want to show in a table from the
axis expression

To exclude a category use ^CatName

To hide a category use [IsHidden=true] after the category name

All methods look the same in the table

Its generally better to hide categories so its clear that the category exists.

Properties of categories are amended using square brackets [ ]

IsHidden is a property of categories, by default its set to false

82 2011 Ipsos
Base and Total

To include a base in the tables, use the function base()


The base is by default included in the table
Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{base(),_1,_2,_3,_4,_5,_6,_7} *
Q2{base(),_1,_2}","Cross Age by Gender")

To hide the base in a table, use isHidden property

Set objTable =
objTableDoc.Tables.AddNew("Table8",Q1{base()[isHidden=true],_1,_2,_3,_4,_5,_6,_7}
* Q2{base() [isHidden=true],_1,_2}","Cross Age by Gender")

To include a total in the tables, use the function total()


The total is NOT included by default in the table

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{..,total()} * Q2{_1,_2}","Cross


Age by Gender")

83 2011 Ipsos
Variable Presentation New Categories combine() and net()

To show combinations/nets of categories


Name 'Label' combine({category1, category2, ..})
The combine() and net() categories work in the same way, they just
display the results differently. Combine creates a new category, Net
does the same and also includes the individual component categories
underneath the new category indented and italicised.

They show a logical combination of or for each category specified. In


the example respondents are included in the Beer category if they
have selected lager or ale. N.B in multicoded questions this is not the
same as adding the counts together

The double dots .. are used to specify the rest of the question is to be
shown as per the mdd

84 2011 Ipsos
Creating nets

Net

Set objTable=objTableDoc.Tables.AddNew("Table1",Q1{base(),_
net1 'Category 1' net({_1,_2,_3}),net2 'Category 2' net({_4,_7,_8}),_
net3 'Category 3' net({_5,_6})}*Q2",Q1 with nets crossed by Gender")

Combine

Set objTable=objTableDoc.Tables.AddNew("Table1",Q1{base(),.., _
net1 'Category 1' combine({_1,_2,_3}),net2 'Category 2' combine({_4,_7,_8}),_
net3 'Category 3' combine({_5,_6})}*Q1",Q1 with nets crossed by Gender")

85 2011 Ipsos
Sorting Tables
We can specify how we sort the rows and columns in a table
objTable.SortRow = "first|last|variable{category}"
objTable.SortColumn = "first|last|variable{category}"

So far all the categories have appeared in tables in the order


they exist in the mdd or as per an axis expression. If needed we
can sort them into an order based on the values in the table
The table object has properties called SortColumn and SortRow
To sort the rows in a table we set a SortColumn to sort by
To sort the columns in a table we set a SortRow to sort by
The row/columns to use is usually the "first" or "last" column
or row. To specify a particular column to sort on use the syntax
"VariableName{CategoryName}"

The special elements such as base, na, dk, other, refused are
not sorted and should be fixed
86 2011 Ipsos
Sorting tables

Sorting Tables - Examples


objTableDoc.Tables["Table1"].SortColumn=Q1{Base}"

objTableDoc.Tables["Table1"].SortColumn=Q1{_1}"

objTableDoc.Tables["Table1"].SortColumn=First"

To fix an element, add [isFixed=true] to it. Some items such as


base(), means and others have the isFixed property set to true as
default. Fixed elements do not change position when sorted.

Set objTable = objTableDoc.Tables.AddNew("Table8",Q1{base(),_1,_2,_3


[isFixed=true],_4,_5,_6,_7} * Q2{base(),_1,_2}","Cross Age by Gender")

87 2011 Ipsos
Tabulating an open variable

Numeric and text questions cannot be tabulated until they have


an axis expression with categories defined. Without this there
would be no rows/columns to show.
In order to tabulate an open variable (numeric or text), we must
first categorize it.
objTableDoc.Coding.CreateCategorizedVariable("Q2","Q2.codes")

Q2.codes is now the categorized version of Q2. We can now tabulate Q2


just like any other categorical variable.

Set objTable = objTableDoc.Tables.AddNew("Table1","Q2.codes*Q1",Age crossed


with gender")

88 2011 Ipsos
Statistical elements and more
Lesson 3
Statistics

Overview

Adding Factors
Mean
Standard Error
Standard Deviation
Mean/Median on numeric variables
Derived/expression

90 2011 Ipsos
Adding Factors (1/2)

Three ways of adding factors


Metadata either MDD or in DMS
On a MDM Document in DMS or in MRS
Axis Expression
In the Metadata
Q1 "Income" categorical[1..1]
{
_1 "Under $15,000" factor(7500),
_2 "At least $15,000 but under $25,000" factor(20000),
_3 "At least $25,000 but under $30,000" factor(27500),
_4 "At least $30,000 but under $35,000" factor(32500),
_5 "At least $35,000 but under $40,000" factor(37500),
_6 "At least $40,000 but under $50,000" factor(45000),
_7 "At least $50,000 but under $75,000" factor(62500),
_8 "$75,000 or over" factor(80000),
_999 "Dont know"
};

91 2011 Ipsos
Adding Factors (2/2)

On MDM Document
objTableDoc.DataSet.MdmDocument.fields[Q2"].categories["_5"].Factor=5
objTableDoc.DataSet.MdmDocument.fields[Q2"].categories["_4"].Factor=4
objTableDoc.DataSet.MdmDocument.fields["Q2"].categories["_3"].Factor=3
objTableDoc.DataSet.MdmDocument.fields["Q2"].categories["_2"].Factor=2
objTableDoc.DataSet.MdmDocument.fields["Q2"].categories["_1"].Factor=1

On the axis expression

Set objTable = objTableDoc.Tables.AddNew("Table2",Q2{_5 [Factor=5],_4


[Factor=4],_3 [Factor=3],_2 [Factor=2],_1 [Factor=1]}*Q1","Cross Region by
Buyers")

92 2011 Ipsos
Statistical elements(Categorical Variables)

In order to add Statistical elements on categorical variables,


factors must be defined

Mean
Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,Mean 'Medie'
mean()}*Q2","Cross Region by Gender")

Standard Error
Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,StdErr 'Standard
Error' stderr()}*Q2","Cross Region by Gender")

Standard Deviation
Set objTable = objTableDoc.Tables.AddNew(Table2",Q1{..,StdDev 'Standard
Deviation' stddev()}*Q2","Cross Region by Gender")

93 2011 Ipsos
Statistical elements (Numeric Variables)

In order to add statistical elements on numeric variables, the


variable name must be inserted in the function
Mean
Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,Mean 'Medie'
mean(Q3)}*Q2","Cross Region by Gender")

Median

Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,Median 'Mediana'


median(Q3)}*Q2","Cross Region by Gender")

To change the number of decimals for statistical elements:

Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,Mean 'Medie'


mean(Q2) [Decimals=2]}*Q3","Cross Region by Gender")

94 2011 Ipsos
Derived, expression, text elements

You can create special derived categories which are computed


from other categories on the axis. Below you can see the
difference between the counts in two nets:
Set objTable=objTableDoc.Tables.AddNew("Table1",Q1{base(),.., _
net1 'Category 1' combine({_1,_2,_3}),net2 'Category 2 combine({_4,_7,_8}),_
d1 Derived category' derived(net2-net1)}*Q1",Q1 crossed by Gender")

You can also create variables based off conditions on other


variables using the expression element.
Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,e1 Younger than 40'
expression(Q3<40)}*Q2","Cross Region by Gender")

You can add empty rows with just a text on the axis
Set objTable = objTableDoc.Tables.AddNew("Table2",Q1{..,t1 This is just text'
text()}*Q2","Cross Region by Gender")

95 2011 Ipsos
Filters
Lesson 4
Applying Filters to Tables

Overview

Operators used when filtering


Functions used when filtering
Dimensions Database
Creating a Table Specific Filter
Creating a Document Level Filter
Creating a filter using the Defaults object
Creating a filter using the Global object

97 2011 Ipsos
Common Operators Used When Filtering

Symbol Description
= Equal to
< Less than
<= Less than or Equal to
<> Not Equal to
> Greater than
>= Greater or Equal to

98 2011 Ipsos
Functions & Operators Used When Filtering

Predefined Functions
- AnswerCount
- ContainsAll tests if all specified answers are included
- ContainsAny tests if at least the specified response is cheked
- ContainsSome

Operators (used for combining expressions)


- AND Tests whether both expressions are True
- OR - Tests whether at least one expression is True
- XOR - Tests whether one expression or the other is True. This is
useful to handle situations where either one is true but not both

99 2011 Ipsos
Common Operators Used When Filtering

Many of the operators used in evaluating logical


statements behave very differently when evaluating
numeric, categorical and text variables
Examples:
If income is stored as a numeric field you can write:
Income < 15000
To select a specific element from a categorical field
you can write:
Gender = {male}

100 2011 Ipsos


Variables in Dimensions Database

Numeric (Long Double)


Number if answered
(null) if not asked

Categorical
SA
{cat_name} if answered
(null) if not asked
MA
{cat1_name, cat1_name,.} if answered
(null) if not asked
All variables have a default value if they are asked, but not answered blank for
strings, {} for SA and MA; for numeric variables a default value must be set.
GRID
vdata
One variable for each iteration: GridName[{iteration_name_n}].QuestionName
{cat_name} if answered
(null) if not asked

101 2011 Ipsos


Dimensions Database Operations

SA
= {cat}
<> {cat}
AnswerCount()
MA
= {cat}
<>{cat}
ContainsAny({cat1,cat2,})
not ContainsAny({cat1,cat2,})
AnswerCount()
OE & Numeric & Loop
Is null
Is not null

102 2011 Ipsos


Creating a Table Specific Filter

The code that applies a filter is of the form:

objTableDoc.Tables["Table5"].Filters.AddNew("MalesOnly",
"ISQ20.ContainsAny({_1})","Only Males")

Parameter 1 simply allows you to name the filter. It is possible to


refer to the filter by name later on in the script
Parameter 2 is the logical expression which determines how the
filter is created
Parameter 3 is the description of the filter which is printed along
with the generated table

Note that the table Table5 must be defined before applying


filter on it

103 2011 Ipsos


Levels
So far our properties and methods have been set for individual tables.
However, there are 3 levels you can work with: Global, Default & Table

The 3 levels affect different tables:


Global - changes affect every table, even if the change is applied at the
end of the script. This is handy for standards you want to see in all
your tables in the script. The global changes are applied when the
script is run, immediately before the tables are populated with data
Default - changes affect every table from the point their declared until
they're removed. This is handy if you want to apply the same change to
a portion of your tables
Table - changes only affect the table specified

The collections are the same structure at each level, so the


methods (AddNew, Remove & Clear) all work in the same way.
Not all collections exist at all levels
104 2011 Ipsos
Creating a Document Level Filter

Rather than using the AddNew method on each table, and


therefore declaring all the filter parameters multiple times, we
could have created the filter once and then referenced it later
using the filter name along with the Add method

Creating a Document Filter


objTableDoc.Filters.AddNew("MalesOnly","ISQ20.Contains
Any({_1})","Only Males")

Set objTable
Obj TableDoc.Tables[0].Filters.Add(MalesOnly)

105 2011 Ipsos


Creating a Document Level Filter

You can also add a filter directly on the Table object rather than
referencing the table from the Table Doc Object by name

Set objTable = objTableDoc.Tables.AddNew("T2","Q2_recode*Q3","My


second table")
objTable.Filters.AddNew("F1","Q1={_1}","Males only")

NB: As you will most likely be using the same object name to set different
tables throughout your script, use this right after creating your tables,
before objTable changes definition.

106 2011 Ipsos


Creating Filters Using the Table Defaults Object

If we had a whole block of tables in sequence to which we


wished to apply a specific filter it will be more efficient to
create a default filter which would apply to all subsequent
tables
Applying a filter via the Table Defaults:

objTableDoc.Default.Filters.AddNew("MalesOnly","ISQ20.C
ontainsAny({_1})","Only Males")

In order to remove a filter contained within the default object:

objTableDoc.Default.Filters.Remove(MalesOnly)

107 2011 Ipsos


Creating Filters Using the Table Global Object

Applying the filter is very similar to the Table Default object

objTableDoc.Global.Filters.AddNew("MalesOnly","ISQ20.C
ontainsAny({_1})","Only Males")

We just reference the Global object rather than the Default


object

108 2011 Ipsos


Grid Tables
Lesson 5
Grid Tables

Overview

Summary Table
One Table for each statement

110 2011 Ipsos


Summary Table (AddNewGrid Method)

Rather than using the AddNew method we are instead using


the AddNewGrid method

Set objTable =
objTableDoc.Tables.AddNewGrid("GridTable","ISQ45",,"ISQ45
Summary Table")

Parameter 1 (Name) allows us to specify the name of the table


Parameter 2 (Field) we only need to specify the grid variable itself
Parameter 3 (Orientation) optional parameter, missing out this
parameter sets the
table orientation to be the default according to the metadata file (1 =
iteration variable in the Rows, 2 = iteration variable in the columns)
Parameter 4 (Description) specifies a description in the left-header of
the table

111 2011 Ipsos


Summary Table (AddNew Method)

Additional variables cannot be nested or concatenated to


the grid variable when using the AddNewGrid method.
If additional variables are required within the table the
AddNew method must be used:

Set objTable =
objTableDoc.Tables.AddNew("GridTable1",Q1*Q1.Q1_scale", Q1
Summary Table")

There are two main differences when using the AddNew


method instead of the AddNewGrid method:
Both the row and column variables have to be explicitly stated in
the table specification
The orientation parameter is no longer applicable as the
orientation is determined by which variables are entered as row
and column variables

112 2011 Ipsos


One Table for each statement

To build a table on a specific statement (iteration) crossed with


anything, specify the iteration in the table definition:
Set objTable =
objTableDoc.Tables.AddNew(Q1_1,Q1[{_1}].Q1_scale*Q2", Q1.1
Allergy treatment products in the spring /summer")

Best Practice:
A for instructioncan be used to iterate to all statements of the grid
and build one table for each one:

dim i
for i=1 to 3
Set objTable = objTableDoc.Tables.AddNew("ISQ1_"+ctext(i),
"ISQ1[{_"+ctext(i)+"}].Q1_scale*Q1","ISQ45_"+ctext(i)")
next

113 2011 Ipsos


Extras
Lesson 6
Extras

Overview

Cell items (counts / row % / col %)


Suppress empty lines/columns
Sig Tests
Recoding

115 2011 Ipsos


Cell Items

By default a table has counts and col %


To add row %:
objTableDoc.Tables["Table2"].CellItems.AddNew(2)

To remove counts
objTableDoc.Tables["Table2"].CellItems.Remove(0)

Count(0)
Column Percentage(1)
Row Percentage(2)

NB: The above codes are valid only when adding CellItems

Default Object can be also used for CellItems

116 2011 Ipsos


Number of Decimals

By default in the tables, the percentages have one decimal.


To change the number of decimals from one to two it must:
Remove the existing percentages
Add the percentages with two decimals

objTableDoc.Default.CellItems.Remove(1)
objTableDoc.Default.CellItems.AddNew(1,2)

117 2011 Ipsos


Suppress Empty Cells & Operations
To remove cell elements, you must reference their current position,
starting at 0. Default you have counts at position 0 and column % at
pozition 1.
If, for example, you remove counts then add row % and then add
counts, you will have column % at position 0, row % at position 1 and
counts at position 2. To remove counts now, youd have to type:

objTableDoc.Default.CellItems.Remove(1)

To supress empty lines


objTableDoc.Default.Rules.AddNew()

To supress empty columns

objTableDoc.Default.Rules.AddNew(,1)

118 2011 Ipsos


Statistics - Objectives

Statistical tests are useful to highlight which differences between


figures are meaningful and which are not. We will look at how to
apply these tests. The most common test Column Proportions is
used as an example. Other tests are applied in the same way. We can
specify which columns to test and in what combination.

Objectives
Applying a statistical test to a table
Specifying Column Labels
Specifying Columns to Test
Changing properties of the Test including Sig Level

119 2011 Ipsos


Significance Tests (1/3)

Steps to follow for defining Sig Tests


Define the Test. Most used are Column Proportions and Column
Means
objTableDoc.Default.Statistics.Add("ColumnProportions")
objTableDoc.Default.Statistics.Add("ColumnMeans")

Define the Column IDs


objTableDoc.Tables["TableX"].Statistics.ColumnIDs = "ABCDEFGH
`to jump a column use:
objTableDoc.Tables["TableX"].Statistics.ColumnIDs = "ABC.EFGH

Define the columns tests

objTableDoc.Tables["TableX"].Statistics. TestColumns = "AB,CD,EF,GH

120 2011 Ipsos


Significance Tests (2/3)

Define Small Base, Min Base

objTableDoc.Default.Statistics[0].Properties["MinBase"] = 30
objTableDoc.Default.Statistics[0].Properties["SmallBase"] = 50

Define Significance Level


objTableDoc.Default.Statistics[0].Properties["SigLevel"] = 5
objTableDoc.Default.Statistics[0].Properties["SigLevelLow"] = 10

Important:
As you noticed, the Column IDs and the Column Tests are defied to
the table level because headers can be different from table to table
If the Columns IDs and Column Tests are consistent to the document
level, functions or for can be used to define them only once

121 2011 Ipsos


Significance Tests (3/3)

In order to improve run times on 64 bit machines, always include


this line in all scripts that have statistic tests:

objTableDoc.Default.Statistics.GridDetectionMethod = 1

122 2011 Ipsos


Recoding

The syntax for building new variable based on existing variables

objTableDoc.Dataset.Variables.AddNewVariable("!
buyers "Buyers Non Buyers"
categorical [1..1] {
_1 "Buyers" expression("ISQ40a.ContainsAny({_1,_2,_3})"),
_2 "Non Buyers" expression("Not ISQ40a.ContainsAny({_1,_2,_3})")
}
!")

123 2011 Ipsos


Data Management Scripts
Lesson 7
Data Management Scripts

Overview

Recoding
Average number of Mentions
Side by Side tables
Top Box / Top 2 Box
Database Merging
Weighting

125 2011 Ipsos


What is DMOM?

Definition
DMOM is method by which data management solutions are
created
Stands for Data Management Object model.
Is a series of library scripting functions used to create data
management solution.
Process/reads in a survey and dataset (known as input),
modifies or manipulates the information stored in there
exports this revised survey and dataset (known as output)

126

126 2011 Ipsos


Reading data in (InputDataSource)

Definition
The InputDataSource section defines the input data source for the data transformation.
Overview
References input data and survey files
Typing code manually or use macros and wizards
Input metadata and data files located in same directory as the data management script.
Format:

NOTE: SelectQuery filters the view of the input data files. Without this all records selected.
<Description of Event>optional, but recommended to describe nature dataset
<InputName> referenced in other Data management events
All the keywords in a Data Management are case insensitive

127

127 2011 Ipsos


Exporting data out (OutputDataSource)

Definition
The OutputDataSource section defines the output data source for the data transformation.

128

128 2011 Ipsos


Create New Variables in the Database

When creating a Data management script solution there may be times where
we need to create additional derived variables, that we know will be needed in
the newly exported output data files.
The Metadata section of a Data Management script allows us to accomplish
that.
Definition
The Metadata section is an optional section that can be used to define new
variables in the metadata that is used for the transformation. The code in
the Metadata section must be valid mrScriptMetadata
This is the same language used to create variables under IOM (Interviewing
Object model).
Example
Metadata(ENG,Question,Input)
<metadata variables>
End Metadata
129

129 2011 Ipsos


Events

An event is essentially a sub-routine within the Data Management Script.

The code within each event is processed at pre-determined points in the


DMS process.

You may write your events in any order in your Data Management Script but
they will always be processed in the order pre-determined by the DMS
architecture.

The next slide shows a simplified diagram of the DMS process.

130 2011 Ipsos


Data Management Script Procedure
1
OnBeforeJobStart InputDataSource
Metadata Case Data Update Query
3
Merge Metadata in
InputDataSource and 4 Select Query
Metadata event

8
New OnJobStart
Metadata Variables
9 Repeat for
OnNextCase each
Respondent
5 2
10
GlobalSQL
Variables
OnBadCase
6
OnAfterMetadata 11
Transformation Create Output OnJobEnd
Structure
7
Update Query
12

OnAfterJobEnd Metadata Case Data


13

OutputDataSource
131 2011 Ipsos
Data Management Script Procedure
OnBeforeJobStart Event Section
This is typically used to set up card and column allocations in the input data source's metadata
in a job that exports case data to Quantum.

Metadata Section
The metadata in the InputDataSource section is merged with any metadata defined in the
Metadata section.
The merged metadata is then available to the input data source so any new variables (from the
Metadata section) that have been included in the Select Query statement will be returned by
the query.

OnAfterMetaDataTransformation Event Section


Runs after the metadata merge is complete and is typically used to set up card, column, and
punch definitions in the new variables created in the Metadata section.

132 2011 Ipsos


Data Management Script Procedure

OnJobStart Event Section


Run before the processing of the individual cases and is typically used to set up global variables
that are required in the OnNextCase and OnBadCase sections.

OnNextCase Event Section


Processed for each case included in the transfer and is typically used to clean the case data.

OnBadCase Event Section


Processed for each case that has failed validation and will not be transferred to the output data
source, and is typically used to create a report of bad cases.

OnJobEnd Event Section


Run after the processing of the last case has been completed and is typically used to close
report files and set up weighting using the Weight component.

OnAfterJobEnd Event Section


Processed after all other processing has finished. This is typically used to set up tables or to e-
mail a report or notification.

133 2011 Ipsos


Data Management Script Procedure

InputDataSource Select Query


Used to filter the data

Modify the SelectQuery inside the InputDataSource


From : SelectQuery = "SELECT * FROM VDATA"
From ..Where: SelectQuery = "SELECT * FROM VDATA WHERE condition"

134 2011 Ipsos


Introduction to the File System Object

There are many occasions when we need to access to the file system
from within a Data Management Script. Such as:

Copying outputted files to a shared drive location for Researchers


and/or clients to collect.
Making a copy of an MDD file so we can add extra information before
processing it.
Writing information or data to external text files reports, logs, custom
delimited files.
Renaming output files.
Deleting temporary files.

In order to do this we reference the File System Object (FSO) model


within our script which provides an object-based tool for working
with folders, files and drives.

135 2011 Ipsos


Introduction to the File System Object

The FSO model gives you the ability to work with files and
folders to:
Create
Modify / append
Move
Delete
Determine if and where they exist
Access information such as:
Path names, file extensions, dates created, modified or last accessed
Get drive information:
Number of drives, available space

FSO can return information for files, folders and drives in


objects which we can use in loops to perform repeated tasks:
136 2011 Ipsos
Referencing the File System Object
The FSO can be referenced at any section or event in a Data Management Script
except the following:
Input & OutputDataSources
Logging Section
Job Section

Typically use this in the OnBeforeJobStart, OnJobStart, OnJobEnd and


OnAfterJobEnd sections to manage files before and after the Data Management
Script runs.

In the OnNextCase we can use it to stream text information to create reports at


the respondent level.

By creating the FSO object as a global DMS variable in OnBeforeJobStart or


OnJobStart we can write report or custom data output record for each
respondent by referencing it from within OnNextCase event.

NOTE: The FSO can be referenced in all Data Collection scripts, i.e. interview
routing, data management, tabulation or mrScriptBasic files.

137 2011 Ipsos


Referencing the File System Object

Use the CreateObject method to add the FileSystemObject object


into a temporary variable.

Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")

It is important to remember to clear the FSO object at the end of the


event section to remove it from memory.

Set FSO = null

We reference the FSO temporary variable within our DMS when


performing file, folder and drive tasks.

138 2011 Ipsos


Referencing the File System Object
Copy

FSO.CopyFile("OriginalFilename","CopyFilename",overwrite)
FSO.CopyFolder("OriginalFoldername","CopyFoldername",overwrite)

Move / Rename

FSO.MoveFile("OriginalFilename","NewFilename")
FSO.MoveFolder("OriginalFoldername","NewFoldername")

Delete

FSO.DeleteFile("Filename",force)
FSO.DeleteFolder("Foldername",force)

Check File, Folder or Drive Exist


These checks return a boolean true or false value and are typically used in logic queries in If or Select Case statements.
FSO.FileExists("Filename")
FSO.FolderExists("Foldername")
FSO.DriveExists("T:")

Create a New Folder

FSO.CreateFolder("FolderName")

139 2011 Ipsos


OnNextCase

Definition
The OnNextCase event is used to define procedural code that is to
be applied to each selected case or record.
Overview
Examples
Cleaning any records for invalid or irrelevant responses
Using logic to build or persist new derived variables from Metadata
event
Dropping entire records from data set i.e. failed screener
Accessing any global objects i.e. writing to an Excel file
Example
If ISQ40A.containsAny({_1,_2,_3}) then Buyers={_1}
If not ISQ40A.containsAny({_1,_2,_3}) then Buyers={_2}

140 2011 Ipsos


Average Number of Mentions

DMS

Metadata(ENG_GB,Question,Label)
ISQ40Av Av No of Mentions long;
End Metadata

Event(OnNextCase "Data Processing")


if ISQ40a is not null then ISQ40Av=ISQ40a.AnswerCount()
End Event

MRS

Set objTable=objTableDoc.Tables.AddNew("TableQ40a",
"ISQ40a{..,Av Average No of Mentions mean(SQ40Av)}*
ISQ20",Average Number of Mentions")

141 2011 Ipsos


Side by Side tables

DMS
Metadata
Q41Q41a "ISQ41.ISQ41a Side by side" loop
{
ISQ41 "Q41",
ISQ41a "Q41a"
} fields
(
GV1 "" categorical [1..1]{
_1 "I buy it myself and I choose the brand",
_2 "I buy it myself, even if I dont always choose the brand",
_3 "I choose the brand, but someone else buys it for me",
_4 "Someone else buys it and I dont choose the brand",
_5 "I use whatever is available at home"}
)expand grid;

OnNextCase Event
Q41Q41a[0].gv1=ISQ41
Q41Q41a[1].gv1=ISQ41a

MRS Set objTable=objTableDoc.Tables.AddNewGrid("SbS","Q41Q41a",2,"Side by Side")

142 2011 Ipsos


Top Box/Top 2 Box

DMS
Metadata
ISQ45TB "Brand Equity" categorical[1..]
{
_1 "Allergy treatment products in the spring /summer",
_2 "Allergy treatment products in the autumn/winter",
_3 "Allergy treatment products on average through out the year
}

OnNextCase Event
dim i, check
check=0
for each i in ISQ45.categories
if ISQ45[ccategorical(i)].scale.containsAny({_1,_2}) then ISQ45TB = ISQ45TB + ccategorical(i)
if ISQ45[ccategorical(i)].scale is not null then check=1
next
if answercount(ISQ45TB)=0 and check=1 then
ISQ45TB = {}
end if

143 2011 Ipsos


Top Box/Top 2 Box

MRS
Set objTable=objTableDoc.Tables.AddNew("ISQ45T2B","ISQ45TB*ISQ20","Q45 Top 2 Box")

144 2011 Ipsos


Database Merging

Vertical merge:
two or more input data sources and one output data source
See \\rofs01\Dimensions\01. Training\02. Ipsos Training
Materials\05.DP\Merge\MergeVertical.dms

Horizontal Merge:
two or more input data sources and one output data source+
JoinKey defined in each input data source
See \\rofs01\Dimensions\01. Training\02. Ipsos Training
Materials\05.DP\Merge\MergeHorizontal.dms

145 2011 Ipsos


Merge Data Horizontal Merge
How a Horizontal Merge Works
A horizontal merge combines the variables from cases in two or more input
data sources into a single case, which is then written to the output data.
Cases are combined (or "joined") only when they have the same value in
their key fields.

This diagram shows a full


horizontal merge of two input
data sources that are joined
using Respondent.Serial.
The default type of merge, is
a "full" horizontal merge. It
will write to the output data
any cases that have not
been joined. This ensures
that all cases on all input
data sources are written to
the output data.

147 2011 Ipsos


Join Commands

The commands we use to join data files are:

JoinKey
The variable used for matching across data files.
If you do not specify a JoinKey the DMS will attempt a vertical merge instead
(see next lesson).

JoinType
How the data files should be merged.
Required on the Master Input Data Source Only.

JoinKeySorted = True
When running a horizontal merge all input data sources are sorted
automatically.
If your data files are already sorted, you can speed up processing by switching-
off the sorting by using this command.

148 2011 Ipsos


JoinType Definitions

JoinType Description
All cases on all input data sources are written to the output data.
Full Cases with identical JoinKey values are combined before writing.
This is the default behavior if JoinType is not specified.
Only cases with identical JoinKey values on all input data sources are written to the
Inner output data.
The cases will be combined before writing.
Only cases with JoinKey values that exist in the master data source are written to the
Left output data. Cases with identical JoinKey values are combined before writing.

149 2011 Ipsos


Define the Input Data Source

NOTE: The first data source is known as the master data source.

InputDatasource(myMasterDataSource)
ConnectionString = "Provider=mrOleDB.Provider.2;_ Add these two
Data Source=mrDataFileDsc;_ Join Commands
Location=First.ddf;_
Initial Catalog=First.mdd"
for matching
SelectQuery = "SELECT * FROM VDATA" purposes
JoinKey = "Respondent.Serial"
JoinType = "Left"
End InputDatasource

InputDatasource(mySecondInputDataSource)
ConnectionString = "Provider=mrOleDB.Provider.2;_
Data Source=mrDataFileDsc;_ Define the
Location=Second.ddf;_ variable to be
Initial Catalog=Second.mdd"
SelectQuery = "SELECT * FROM VDATA"
used for
JoinKey = "Serial" matching
End InputDatasource

150 2011 Ipsos


Specify Output Data Source

OutputDatasource(myOutputDataSource)
ConnectionString = "Provider=mrOleDB.Provider.2;_
Data Source=mrDataFileDsc;_
Location=Merged.ddf;_
MR Init MDM DataSource Use=2;_
MR Init Overwrite=1"
MetaDataOutputName = "Merged.mdd"
End OutputDatasource

151 2011 Ipsos


Merge Data Vertical Merge
How a Vertical Merge Works
In a vertical merge, the case data in each input data source is written in its
entirety to the output data.
The case data for the first data source is written first, followed by the case
data for the second and any subsequent input data sources.

All the input metadata is


merged.
The output metadata and
the output case data contain
all of the variable names
from both input metadata
files.
Nulls are inserted into the
output case data for those
variables that did not exist in
the input data source.

153 2011 Ipsos


Creating a Vertical Merge

Vertical merges match data based on Variable Name


and add new case data and are typically used to:

Combine survey data from different waves of a tracking


project.

Combine data for different countries of a multi-country


project each using the same or similar Interviewing Script.

154 2011 Ipsos


Define Data Sources

Add the code for your first (master) data source.


Reference the file1 text substitution in place of the file name.

InputDatasource(InputWave1)
ConnectionString = " _
Provider = mrOleDB.Provider.2; _
Data Source=mrDataFileDsc; _
Location = " + file1 + ".ddf; _
Initial Catalog = " + file1 + ".mdd"
End InputDatasource

Repeat this by creating InputWave2 and InputWave3


Remember to reference the file2 and file3 text substitutions respectively.

155 2011 Ipsos


Define Data Sources

Now create the Output data source, this time referencing the fileall text
substitution.

OutputDatasource(OutputAllWaves)
ConnectionString = " _
Provider = mrOleDB.Provider.2; _
Data Source = mrDataFileDsc; _
MR Init Overwrite=1;_
Location = " + fileall + ".ddf"
MetaDataOutputName = fileall + ".mdd"
End OutputDatasource

156 2011 Ipsos


Weighting
Weighting

Most of the weighting process in Dimensions in done within a


DMS Script, OnJobEnd Event

Steps to follow:
1. In the metadata section define the weighting variable
2. Initiate Weight Engine
3. Define Weighting Report File
4. Define the weighting axis
5. Define the weighting matrix
6. Execute the Weighting
7. Write the weighting Report in the file defined above

158 2011 Ipsos


Weighting types

Factor Weighting You use factor weighting when you already know
the weighting factor for the respondents in each population group on
which you are basing your weighting
Target Weighting You use target weighting when you know the
total number or proportion of respondents that you want to appear
in each cell of the table.
RIM Weighting this is the most used; you use it when
You want to weight according to various characteristics, but you do not
know the relationship of the various combinations of those
characteristics.
You want to weight using target weighting but there are no respondents
who fulfill the requirements of one or more of the cells of the target
weighting table.
For more information on weighting, please visit:
http://pic.dhe.ibm.com/infocenter/spssdc/v6r0m1/topic/com.spss.d
dl/weight_overview.htm

159 2011 Ipsos


Rim weighting
DMS
Metadata
1.In the metadata section define the weighting variable
pond "Variabila de ponderare" double usagetype("Weight");

JobEnd Event
dim WgtEng, Wgt, fso, ReptFile
2.Initiate Weight Engine
set WgtEng = dmgrJob.WeightEngine

'3.Define Weighting Report File


set fso = CreateObject("Scripting.FileSystemObject")
Set ReptFile = fso.CreateTextFile("WeightRP.htm", true)

'4.Define the weighting axis


set Wgt = WgtEng.CreateWeight("pond","ISQ15, ISQ20", wtMethod.wtRims)

'5.Define the weighting matrix


wgt.Rims["ISQ15"].Targets="5;5;5;4;4;4;4"
wgt.Rims["ISQ20"].Targets="15;16"

6.Execute the Weighting


wgtEng.Execute(Wgt)

'7.Write the weighting Report in the file defined above


ReptFile.write(Wgt.Report)

160 2011 Ipsos


Weighting

MRS
objTableDoc.Default.Weight="pond

When Weighting is applied, Unweighted Base element is


automatically created. To hide this element, use:

objTableDoc.Default.Properties["AutoUnweightedBases"] = False

161 2011 Ipsos


Open Ended Tables
Lesson 8
Open Ended Tables

Overview

Includes codes in the database


Codeframe Processing

163 2011 Ipsos


Open Ended Tables

Steps to follow for creating open ended tables:


DMS
Create categorical question for each codeframe
Insert codes in the created question, for each respondent and each
question

MRS
Create the table for each OE Question, including nets and other data
processing

164 2011 Ipsos


Categorical question for each OE variable

Metadata(ENG_GB,Question,Label)

codeframe define
{
_1 Cute/Clever
_2 Amusing/humorous/entertaining,
_3 Exciting/holds attention/interesting,
_3001 Surprising,
_3002 Intriguing,
_4 Appealing/attractive/pleasant,
_4021 Clean / Cleanliness,
_4023 Easy / Easy to watch,
_4024 Happy/cheery

}

Qf4aOE Main Idea categorical[1..]


{
use codeframe
}

End Metadata

165 2011 Ipsos


Create the Tables

Set objTable=objTableDoc.Tables.AddNew("MI", "Qf4aOE{base(),_


N1_1 'Respondents NET' net({_
N2_1 'Favourable SUB-NET' net({_
N3_1 'Cute NET' net({_1}),_
N3_2 'Amusing NET' net({_2}),_
N3_3 'Exciting NET' net({_3.._3002}),_
N3_4 'Appealing NET' net({_4.._4024})})})}*ISQ20", "QF4a. Main Idea")

166 2011 Ipsos


Reading the codeframe

To generate both the categories and the axis expression for an


coded question, you can use the DimCodeframe application.
This application read the codeframe, under this conditions:
Codeframe must be .xls (not .xlsx)
The first line in the codeframe must be a header (the app ignores
it)
This should be followed by BEBs (optional).
After this we should have a row with the key word StartJoc (case
sensitive) in the first cell.
The codeframe should be in the following rows, with code in the
first cell and label in the second.
The code must be formatted as number with 0 decimals.
In the case of Nets, the first cell must be the keyword NET + the
level of the net.

167 2011 Ipsos


Reading the codeframe

The Codeframe file must have the following format:


Header Whatever

StartJoc

Net1 **RESPONDENTS NET

Net2 **FAVOURABLE(SUB NET)

Net3 Cute/clever

1 Cute/clever

Net3 Amusing/humorous/entertaining

2 Amusing/humorous/entertaining

Net3 Exciting/holds attention/interesting

3 Exciting/holds attention/interesting

3001 Surprising

3002 Intriguing

Net3 Appealing/attractive/pleasant

4 Appealing/attractive/pleasant

4021 Clean / Cleanliness

4023 Easy / Easy to watch

4024 Happy/cheery

168 2011 Ipsos


Insert codes in the created question the ASI way

Codes are inserted in the database in


the OnNextCase event in the DMS.
To quickly create the syntax, you can
use the Codes.xla Excel macro in the
code file.

169 2011 Ipsos


Insert codes in the created question the ASI way

Event(OnNextCase "Data Processing")


If Respondent.ID =20212177 then QF4aOE=Unique{_148,_85,_1,_44,_64,_98,_161}

End Event

170 2011 Ipsos


Insert codes in the created question the MKT way

Save the code file as xls.


Read the file into SPSS Statistics.
Format the SAV file and save it:
Make sure the key (ID, Respondent Serial) is formatted similar to
its correspondent in the mdd.
Make sure each code variable is a numeric with 0 decimals in
SPSS.
For each variable, add Value 1 with label 1. This will force
Dimensions to read these variables as categorical as opposed to
numerical.
Merge your mdd+ddf base with the SAV code file.

171 2011 Ipsos

Você também pode gostar