Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Assign respondents to group based on response to numeric question (zip code)

We are doing a study among residents of a specific state.  We are verifying their residency via zip code.  There are roughly 700 zip codes across the state.

The client has divided the state into six regions, each region contains ~110 zip codes.

The zip code question set up as a numeric question and I am trying to figure out how to assign a respondent to one of the six regions based on their response to the numeric question.

For example:
zip codes 12345,  52186, 25168, and 11258 should be assigned to REGION1
zip codes 12346, 98765, 54678, and 67841 should be assigned to REGION2

Unfortunately, zip code assignment doesn't always make sense so I cannot simply assign all zip codes in a range to a specific region (e.g. 12345 thru 13345).  Rather the inclusion of zipcodes within regions is truly done on a case-by-case basis.

I have scoured the forums for two days looking for an answer and even called Sawtooth support.
asked Jul 13, 2018 by Nwiggin Bronze (1,930 points)

1 Answer

+1 vote
Here's a skip logic you can try:

Begin Unverified Perl
my $zipCodeQuestion = 'ZipCodeQ';
my %zipCodes = (
    12345 => 1,
    23456 => 1,
    34567 => 1,
    45678 => 1,
    56789 => 1
return exists $zipCodes{GETVALUE($zipCodeQuestion)};
End Unverified

"ZipCodeQ" must be replaced with the name of the numeric question representing the zip code.  Lines 4-8 should be copied and updated as necessary to check for all zip codes you want to match with this given skip.  (If you have all zip codes in a simple list, an advanced text editor may be useful in adding the "=> 1," after each one.)

With your large number of zip codes, please test to ensure that the code is performing as quickly as you need.
answered Jul 13, 2018 by Zachary Platinum Sawtooth Software, Inc. (216,800 points)
Zachary always comes up with some neat ideas. No difference here where he is using an array.

One trick in the past I have used is to pop the postcodes into a parent list. That's an easy copy and paste. Call it PostcodeList.

I then create a constructed list as follows ...
Begin Unverified Perl
 my $i=1;
 for($i=1; $i<=100; $i++)
   if (VALUE("Q1") eq LISTLABEL("PostcodeList",$i))
End Unverified

Then I use ListLength(PostcodeConList)=0 as logic in my skips.

This has performed very smoothly when I have had hundreds, even over 1,000 postcodes in my parent list.

Good luck.
I'm dealing with a similar issue where I want to match the zipcodes entered in a question and the state entered in another. I'm missing here to understand how you connect the Perl hash code to the original question about the regions. Where does it say that a particular zipcode should be part of a region here?