Modifying SPSS data export

More
4 weeks 18 hours ago #189012 by Matadeleo
Hi guys,

I'm trying to improve the export for multi-choice questions, so it's easier to use in tabulation software. Here is the goal:



In the /admin/export controller, I can only find code used to generate an SPSS syntax file.

I've managed to remove the Value Label for "Not selected", and instead of using the label "Selected" I pull in the actual label using the code below:
// Print out the value labels!
echo "VALUE LABELS  {$field['id']}\n";
 
$i = 0;
foreach ($answers as $answer) {
	$i++;
 
	if ($field['SPSStype'] == "F" && isNumericExtended($answer['code'])) {
		$str = "{$answer['code']}";
	} else {
		$str = "\"{$answer['code']}\"";
	}
 
	// If multi-choice, use variable label as value label
	$title = $field['VariableLabel'];
	preg_match("/\[(.*)\]/", $title , $matches);
	$valueLabel = $matches[1];
 
	if ($i < count($answers)) {
		echo ($field['LStype'] == "M" ? " $str \"{$valueLabel}\"\n" : " $str \"{$answer['value']}\"\n");
	} else {
		if ($field['LStype']=="M") {
			echo ($answer['code'] == 0 ? ".\n" : " $str \"{$valueLabel}\".\n");
		} else {
			echo " $str \"{$answer['value']}\".\n";
		}
	}
}

This gets us to the "current output", but as you can see, we still have the 0 values in the data (editing the export file only affects the labels).

Is there a way to remove the 0 values on multi-choice questions?

Please Log in or Create an account to join the conversation.

More
4 weeks 17 hours ago #189014 by jelo
Replied by jelo on topic Modifying SPSS data export
I recommend to place a feature request into the Bugtracker. There are not many users here using SPSS, but the feature request will help to raise awareness.

Did you try to use a few lines of SPSS Syntax to change the cell content.
Modifying the core php code might be a bit tricky with all the updates.

What version of LimeSurvey do you use?

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users

Please Log in or Create an account to join the conversation.

More
4 weeks 17 hours ago - 4 weeks 17 hours ago #189017 by Matadeleo
Build: Version 3.17.16+190906

Looking at previous builds, this particular code seems unchanged since as far back as 2.0 and maybe earlier

There is maybe the possibility of inserting syntax code where the software generates the labels, but that would be a messy, hacky solution. Ideally we would not generate the zeros for multi-choice at all, rather than fixing them in post! :)

Something like this, before the execute command
// Untested code
foreach ($fields as $field) {
 	if $field['LStype'] == "M" {
		echo 'replace(' . $field['title'] . '),0,"")'.
	}
}


Would be good to see if this is feasible - I'm not comfortable in making a feature request
Last edit: 4 weeks 17 hours ago by Matadeleo.

Please Log in or Create an account to join the conversation.

More
4 weeks 16 hours ago #189019 by Joffm
Replied by Joffm on topic Modifying SPSS data export
Maybe I misunderstand, why you want to get a categorical output.
In SPSS you have to use multiple sets anyway.

So with the setting


I get this


a clean binary output which you can easily change to the categorical output by an SPSS "recode" or an EXCEL macro.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

Please Log in or Create an account to join the conversation.

More
4 weeks 15 hours ago #189021 by Matadeleo
Hi Joffm,

The screenshot you linked is for Excel-export, that option is not available for SPSS export.

The categorical output as you say it, makes it much easier to create a multi-response set from the data in SPSS and in more specific tabulation software.

By default creating a multi-response set from the screenshotted data would create a variable with:

Selected (Q1_1/1)
Not selected (Q1_1/0)
Selected (Q1_2/1)
Not selected (Q1_2/0)
Selected (Q1_3/1)
Not selected (Q1_3/0)

And so on..

Having the data in the way I described would give the much cleaner:

Option 1 (Q1_1/1)
Option 2 (Q1_2/1)
Option 3 (Q1_3/1)

Yes, this could be achieved by exporting the data to SPSS and to excel like you mentioned, but to manually replace the data is time consuming.

My solution so far saves a lot of time creating multi-response sets, and works well, the last step is to get rid of the 0 values to have a clean data file.

Please Log in or Create an account to join the conversation.

More
4 weeks 15 hours ago #189024 by holch
Replied by holch on topic Modifying SPSS data export

Looking at previous builds, this particular code seems unchanged since as far back as 2.0 and maybe earlier

Still, every update can overwrite this file. So either you won't update anymore or you check before every update if there have been any changes to this file. So there is always this risk. If you update manually, then you can always do this, but I guess it would be probably better if this would be adapted in the LS base, wouldn't it? I assume that this might be interesting for others that use SPSS as well.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in or Create an account to join the conversation.

More
4 weeks 14 hours ago #189026 by Matadeleo
Every time we update LS, we rename the export file - run the update and then apply the "fix" to the new file.

It would be amazing to adapt it into the LS base, even if it was just a toggle option like Joffm linked above



I'm happy to keep manually applying the changes (and to update them if the core code changes), if anyone is able to help point me in the right direction to achieve this.

Please Log in or Create an account to join the conversation.

More
3 weeks 5 days ago - 3 weeks 5 days ago #189042 by Joffm
Replied by Joffm on topic Modifying SPSS data export
Sorry, but I do not see your problem.
This is the default SPSS-export.


Creating multiple sets you have the option to select (binary or catagorical)


And with two statements added to the syntax file before you read in the data.
RECODE G01Q01_SQ001 (1=1) (0=SYSMIS).
RECODE G01Q01_SQ002 (1=2) (0=SYSMIS).
RECODE G01Q01_SQ003 (1=3) (0=SYSMIS).
RECODE G01Q01_SQ004 (1=4) (0=SYSMIS).
RECODE G01Q01_SQ005 (1=5) (0=SYSMIS).

VALUE LABELS G01Q01_SQ001
1 "Option 1"
0 "".
VALUE LABELS G01Q01_SQ002
2 "Option 2"
0 "".
...


(I always adapt the syntax file to my needs. On this stage it is the easiest an quickest way.

Then you get



And:
The advantage of a binary export is that you get the frequencies of each item without multiple sets.
The advantage of a real categorical export would be that you have the order the items are selected.

But this is not supported by LimeSurvey.


Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 3 weeks 5 days ago by Joffm.

Please Log in or Create an account to join the conversation.

More
3 weeks 4 days ago #189052 by Indispirit
Although it's not a LS fix, you could automate the Excel part by using a pivot table.

Please Log in or Create an account to join the conversation.

More
3 weeks 4 days ago #189054 by Matadeleo
Hi Joffm, of course this is possible through SPSS as you mentioned. Sorry if I was not clear - the idea is to avoid having to do this.

We don't need to recode it to be categorical, just trying to avoid exporting the zeros for multi-choice to begin with - to avoid the need to get all variables and recode the zeros as sysmis. This is purely to save time.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!