## Copy value from one case to another

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Lunatic_Machine
Posts: 1
Joined: Fri Jul 19, 2013 8:44 am

### Copy value from one case to another

Hello!

I have to analyze a questionaire. The questionaire has three versions (A, B, C). Each person answered only one version eg. person1 answered version A, person2 answered version B etc. Each version contains of 13 questions (3 versions x 13 questions = 39 variables).

Now, I had to calculate the aggregated mean for each variable [sum of values/number of persons who answered the corresponding version of the questionaire]. That was the easy task.
The next step is to add up the means of different variables, eg. A1 [version A question1]+B3+C4.

And here is my problem:
The fact that every person only answered one version of the questionaire means that each case has 26 of the 39 variables missing (or 0, if you like).
The dataset looks like:

Code: Select all

``````ID       A1 A2 A3 B1 B2 B3 C1 C2 C3
-----------------------------------------
person1  1  4  2  0  0  0  0  0  0
person2  0  0  0  2  3  1  0  0  0
person3  0  0  0  0  0  0  1  1  3
``````
In order to sum up the variables I need to copy the values of A1, A2, A3 from person1 to person2 and person3 etc.
RECODE doesn't solve my problem because I don't have fixed values that the 0 could be recoded into (the aggregated means change with every person that is added to the dataset).

The dataset should ideally look like this:

Code: Select all

``````ID       A1 A2 A3 B1 B2 B3 C1 C2 C3
-----------------------------------------
person1  1  4  2  2  3  1  1  1  3
person2  1  4  2  2  3  1  1  1  3
person3  1  4  2  2  3  1  1  1  3
``````
Is there any (easy? ) way to copy the values of one case to another case via syntax?
I could do this by hand via copy&paste but the dataset contains of over 600 cases and 39 variables. A solution via syntax would be the easiest and least time consuming answer.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

### Re: Copy value from one case to another

You probably already have an answer for your question, but just in case, i was wondering if it wouldn't be better to just make a new variable that only contains the number for the questionnaire that was filled out.
Reason is that you tripple your N which may be problematic in some analyses.

So:

ID D1 D2 D3
-------------------
person1 1 4 2
person2 2 3 1
person3 1 1 3

anyway, What you might be able to use is an F-function.

something like this:

if (A1 = 0 & b1 > .01) a1 = b1.
if (a1 = 0 & c1 > .01) a1 = c1.
execute.

[by the way, there is also this: " ~= 0 " , which means not is 0, but I have had some bad luck with that so that's why I always go for the >.01 now).
etc.

you can use excel to copy paste the parts of your syntax that are always the same to the next line, to make writing it easier.
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

### Re: Copy value from one case to another

Your suggested result looks weird. Sure you don't want

Code: Select all

``````ID       Q1 Q2 Q3
-----------------
person1  1  4  2
person2  2  3  11
person3  1  1  3``````
?

If so, use VARSTOCASES and then SELECT IF to drop the empty cases.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com

### Who is online

Users browsing this forum: No registered users and 2 guests