# Choice Modeling - Analyze with Experiment Question (Legacy) - Experiment Question from Sawtooth Dual Format Files

This QScript sets up an Experiment question for a choice-based conjoint study, where the experimental design is contained in a CSV or Excel file that has been set up according to the guidelines specified by Sawtooth. The guidelines can be found on page 19 of this document.

## Technical details

This requires that:

• You have three files:
1. A data file containing variables that describe which choice tasks were seen by each individual (or respondent) and the choices that were made for each task. This file should be imported into a Q project before running this script.
2. A CSV or Excel data file containing the experimental design in the layout specified by Sawtooth.
3. A CSV or Excel file containing the labels for the levels of each of the attributes in the experimental design. Details for creating this file can be found below.
• Each choice task contains the same number of alternatives and that each individual faced the same number of choice tasks. Note that experiments not consistent with the assumption can still be set up manually. See other formats, Choice Modeling - Analyze with Experiment Question (Legacy) - Experiment Question from JMP Files and Experiments Specifications for details on setting up choice models with different specifications.
• Each individual's data is stored in a single case (row) in the data file.

### Overview of what happens when you run this QScript

• When the QScript runs you will be prompted to specify:
1. Which variables contain the numbers of the tasks seen by each individual.
2. Which variables contain the choices selected by each individual in each task.
3. The location and name of the file containing the experimental design.
4. The location and name of a file containing the labels of the levels of each attribute.
5. Whether or not you want to include alternative-specific constants.
• Upon completion of the QScript you will have a SUMMARY table of an Experiment question, which shows the parameters for a multinomial logit model. See Experiments for more information.

### Sawtooth Experimental Design Format

The standard format of an experimental design from the Sawtooth Dual CSV specifications is illustrated in this example:

Note that:

• There is one alternative per row.
• Each unique choice task is given a number, and this is found in the column of the design file called Task#. Thus, in the example above, there are four alternatives per choice set. This should not repeat, even where there are multiple version numbers. Two distinct choice tasks should never have the same value of Task#. The Task# should begin at 1 for the first task, and increase by 1 for each subsequent task.
• The block number is stored in the Version# column. For example, if each individual sees the same choice sets, then the value 1 appears for all the cells in this column; if there two versions of the choice sets, then the number 1 appears next rows in the first block and 2 next to those in the second block. Note that while this column appears in Sawtooth designs, its use is when programming the data collection and it has no role in the analysis, so if you are setting up data manually, you can just assign a 1 to all rows in the design.
• All the values in the design are indicated with consecutive positive integers (i.e., 1, 2, 3, ...). Where a choice set does not contain an attribute, it should be shown as a 1 in the experimental design (as 1 is the index value that everything is else compared against, and thus has a utility of 0). Note that some care should be taken if re-ordering attribute levels within Q in such instances.
• Rows that correspond to a None of these type option are featured as the last alternative in a choice set and all of the attributes have a value of 0 for this row. This in the example above, the fourth alternative in each choice set is a None of these option.

#### The Data File

The data file that contains information on which tasks the individuals saw and which options the individuals chose should be imported into a Q project before running this QScript. There should be one case in the data file for each individual, so that when each individual faces multiple choice tasks, these tasks are spread across multiple variables and NOT multiple cases.

The data set should contain a set of variables that indicate the Task# number seen by each individual in each task, which matches the Sawtooth Experimental Design. For example, if the individuals each make 8 choices then there should be 8 variables, and the first of these variables should contain the Task# number of the first question (i.e., task) seen by each individual, the second variable should contain the set number of the second question seen by each individual, and so on.

The variables that store the individuals' choices should be set with the Variable Type of Categorical and each should contain the number of the option that was chosen by the individual in the corresponding choice task. For example, if there are 3 alternatives per task then the choice variables should contain values 1, 2, and 3. For an experiment where each individual faces 8 tasks, there should be 8 choice variables, with the first containing the value of the choice made by the individuals in the first choice task, the second containing the value of the choice made by the individuals in the second task, and so on. The script will make a copy of these variables to use for the Experiment question, and each will be relabeled as "Choice".

#### Attribute Labels

The file containing the labels for the levels should contain one column for each attribute, with the labels of each level for that attribute labeled in order. For example:

If no file is specified then the attribute levels will be labeled with the numbers as they appear in the experimental design. These can be changed later by highlighting the variables for a single attribute in the Variables and Questions tab and editing the Values (...) to update the labels.

#### Alternative-specific Constants

The option to add alternative-specific constants adds an additional attribute to the Experiment question that has one level for each alternative. This allows for the estimation of a coefficient for each alternative (eg 1st, 2nd, 3rd).

### Other Formats

If converting a design for use by this script then the following conditions must be satisfied:

1. The first three column headers must be Version#, Task#, and Concept#.
2. The column Task# must indicate the numeric label for each of the possible choice tasks in the experiment. This must be sequential, beginning at 1 and ending at the number of choice tasks in the experiment. This number will be repeated for alternatives that belong to each task.
3. Each task must have the same number of alternatives, and this number of each alternative should be contained in the column Concept#. For example, if there are three alternatives in each task then this column will contain the sequence 1, 2, 3 repeated for each task.
4. Each subsequent column must contain an attribute label as its heading, and must contain the level of that attribute that was shown in the alternative and task for that row.

## How to apply this QScript

• Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
• Click on the QScript when it appears in the QScripts and Rules section of the search results.

OR

• Select Automate > Browse Online Library.
• Select this QScript from the list.

## Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

• Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
• Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
• Press Edit a Copy (bottom-left corner of the preview).
• Modify the JavaScript (see QScripts for more detail on this).
• Either:
• Run the QScript, by pressing the blue triangle button.
• Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

### Customizing QScripts in older versions

• Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
• Modify the JavaScript (see QScripts for more detail on this).
• Run the file using Automate > Run QScript (Macro) from File.

## JavaScript

// Setup Conjoint Experiment Question From a Sawtooth CSV format Conjoint Design
// Design described in http://www.sawtoothsoftware.com/support/manuals/cbc-hb-help
includeWeb('QScript Selection Functions');
includeWeb('QScript Utility Functions');
includeWeb('QScript Functions for Setting Up Experiments');

var design_type = "Sawtooth";
try {
CBCSetupFromDesign(design_type)
} catch (e) {
if (e instanceof SetupError)
log(e.message);
else
throw e;
}