DCE internal calculation

Hi SurveyEngine support team,

I am building a DCE which requires internal calculation between attribute levels. For instance, I have various types of travel time attributes, along with a distinct attribute named “Total travel time,” which represents the cumulative sum of all travel time attributes. Similarly, I have diverse price and discount rate attributes, and based on the levels of these two attributes, I intend to compute the discounted price for each scenario.

I’m uncertain whether I can directly derive the values of certain attribute levels and utilize them to calculate another attribute level within each DCE scenario. I would appreciate any suggestions you may have regarding this matter.

Best,
Joseph

Yi,
There are two ways of doing this - static and dynamic

  1. Static - in your experimental design calculate the total travel times in a additional column. then factorise and order this so you get a list of all unique values and give each an index starting at 0. Then in surveyengine create a new attribute called total_time with one level for each unique value, for each respective offset.

This has the advantage of being explicit and visible - but the problem is this could easily be several hundred levels. It’s also pretty brittle.

  1. The second dynamic - is better suited to you case.
    In this case we simply calculate the total time from the levels.

The tutorial is called ‘dynamic levels’ on the tutorials page

Here’s the preview which includes a downloadable zip.

Here’s the basic steps

The Experiment Setup

This experiment has 3 time variables and 2 options (route 1 and route 2). For simplicty we’ll use an unabelled experiment and assume it’s two car journeys.

This experiment might be trying to find out if people value time in traffic lower than driving time and time walking to the car higher than driving

The variables are:

  • Walking time to Car Pickup - wtime

  • Driving time - dtime

  • Time in traffic jam -jtime

  • Walking to to Office - otime

And we want to calculate and display the total time to the respondent.

Setup the experiment like this

Make variables numeric!

Make sure you make each variable numeric - this will both allow you to display the time (inexactly) as text such as (between half and hour and an hour) while associating each level with real numbers (45).

It will also open up access to the numerical variables for the calculations -these will be for the variables above - for route1

  • wtime_route1_value

  • ctime_route1_value

  • jtime_route1_value

  • otime_route1_value

see the dictionary for the real names for your use

Add Total Time as a one level attribute and generate your design.

The Calculation

You will be explicitly calculating this by alternative - as each has different attributes

for route1 - the total time will be the Perl expression (using the $ to denote a variable)

$wtime_route1_value + $ctime_route1_value + $jtime_route1_value + $otime_route1_value

Putting this into a html so it is actually displayed in a browser is below.

<span class='expression'>$wtime_route1_value + $ctime_route1_value + $jtime_route1_value + $otime_route1_value
</span>

Paste this in (in code view </>) to the Total Time single level attribute for each alternative