Data Generator Tips Part 2

Recently,  I needed to generate data for an acbc exercise for testing if I had too many prohibitions.  I would generate about 50 respondents at a time and look at the results.  The problem was that about 10 respondents in 50 were selecting a prohibited pair or triple in the BYO.  The Data Generator just drops the respondent at that point and starts a new one.  To avoid this problem, I wrote some unverified perl for the Data Generator defined values to solve the problem.  I will use the ACBC sample study for this example.  The ACBC sample study has 10 attributes with 3-4 levels per attribute.  Lets suppose I make my prohibitions look like this.

So I have prohibitions with BYO_1, BYO_2, BYO_3, BYO_6, and BYO_8.

In the data generator defined values area I insert the following code for laptop_BYO_1

Begin Unverified Perl

my @OriginalValues = (1..3);
my %UseValues = map {$_ => 1} @OriginalValues;
if (VALUE(‘laptop_BYO_3′) == 4)
{
delete $UseValues{’1′};
}
my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}
if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

End Unverified

for laptop_BYO_2

Begin Unverified Perl

my @OriginalValues = (1..4);
my %UseValues = map {$_ => 1} @OriginalValues;
if (VALUE(‘laptop_BYO_8′) == 3 || VALUE(‘laptop_BYO_8′) == 2)
{
delete $UseValues{’1′};
}
my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}
if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

End Unverified

for laptop_BYO_3

Begin Unverified Perl

my @OriginalValues = (1..4);
my %UseValues = map {$_ => 1} @OriginalValues;
if (VALUE(‘laptop_BYO_1′) == 1)
{
delete $UseValues{’4′};
}
if (VALUE(‘laptop_BYO_6′) == 4)
{
delete $UseValues{’1′};
}
my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}
if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

End Unverified

for laptop_BYO_6

Begin Unverified Perl

my @OriginalValues = (1..4);
my %UseValues = map {$_ => 1} @OriginalValues;
if (VALUE(‘laptop_BYO_3′) == 1)
{
delete $UseValues{’4′};
}
my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}
if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

End Unverified

and for laptop_BYO_8

Begin Unverified Perl

my @OriginalValues = (1..3);
my %UseValues = map {$_ => 1} @OriginalValues;
if (VALUE(‘laptop_BYO_2′) == 1)
{
delete $UseValues{’3′};
}
if (VALUE(‘laptop_BYO_2′) == 1)
{
delete $UseValues{’2′};
}
my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}
if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

End Unverified

Then I click generate.  After about 1 minute the data records are finished and not a single unfinished respondent.  I know this is a lot of code to take in so let me walk through it with some explanation.

my @OriginalValues = (1..3);
my %UseValues = map {$_ => 1} @OriginalValues;

@OriginalValues is a perl array of level values ranging from 1 to 3.  %UseValues is hash that will contain the level values also.  This might be considered redundant until you learn why I have the hash of level values.  The code that follows will be removing the level values that become prohibited, these we want to remove by level value, not an index.  If we operated on an array, we would have to search through the array for the value and delete the index.  With a hash, this becomes a simpler command.

if (VALUE(‘laptop_BYO_2′) == 1)
{
delete $UseValues{’3′};
}

These lines say if the level value chosen for attribute 2 in the BYO is 1, then remove the level value 3 as a possible choice.

my @Values = ();
if (keys %UseValues == 0)
{
@Values = @OriginalValues;
}
else
{
@Values = keys %UseValues;
}

These lines state if %UseValues is empty, i.e. there are no possibilities left, then we have too many prohibitions in place.  There is nothing we can do except pick anything because not matter what it will fail.  So we assign @Values to @OriginalValues.  Otherwise we just assign the level values in %UseValues to the array @Values.  These are the levels that will still work to avoid a prohibition problem.

if (@Values == 1)
{
return $Values[0];
}
return $Values[INTEGER(0, $#Values + 1)];

These lines state if there remains only one level to choose, then just pick that one.  Otherwise randomly choose a remaining level and return it.

Hopefully, this can help you in the future for testing Conjoint/MaxDiff exercises.

Lighthouse Studio

Lighthouse Studio (formerly SSI Web) is our flagship software for producing and analyzing online and offline surveys. It contains modules for general interviewing, choice-based conjoint, adaptive choice-based conjoint, adaptive choice analysis, choice-value analysis, and maxdiff exercises.

Try Lighthouse Studio

  Buy Lighthouse Studio