create new vars from a range of existing vars based on non-missing

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

create new vars from a range of existing vars based on non-missing

pabstnjazz
Dear List,

I have a scale comprised of 12 items, which I would like to examine more closely. My problem is that the formulation of the items is based on answers earlier in the questionnaire (a choice of 3 groups out of 16), so that the data for these 12 items is represented by 560 variables (the items ask for perceived similarity between the groups that were chosen before, so there are as many variables as hypothetically possible combinations of group pairs times the number of scale items). Every respondent has 12 valid values within these 560 variables, the rest are missing.

Is there a possibility to tell SPSS (v22) to "transport" the values of the 12 valid variables into 12 new variables? For example, transport the first value that is not missing within a defined range of variables (e.g., v_1 to v_560) to v_1new, the second one to v_2new, and so forth?

Theoretically, I know which values are valid for every respondent, based on his or her answers to the item that determines the formulation of the mentioned 12 item scale. Thus, I could create 12 new variables and tell SPSS to fill in the respective values. For example, if a person chose groups 1, 4, and 15, he or she will also have answered variables v_12, v_28, v_74, v_78, v_129, v_222, v_322, v_432, v_454, v_500, v_544, v_568. But it would take me a couple of days, if not longer, only typing if- statements for these operations, because the 12 variables that will have been answered can only be identified unequivocally when I know which 3 groups were chosen, which means 580 (i.e. possible chosen group scenarios) if-statements for every one of the twelve items (I'm not entirely sure about this; I hope it's possible to fill in the 12 variables at once for every possible group scenario).

Also, I am pretty fixated at creating 12 new variables to analyse the scale's properties. Do you see another possibility to describe the characteristics of my scale? I have tried to describe my problem as concisely as possible. If you need more information, please feel free to ask. I will be very grateful for any hints in the right direction.

Kind regards,
Jan

Reply | Threaded
Open this post in threaded view
|

Re: create new vars from a range of existing vars based on non-missing

Maguin, Eugene
I think (not sure) that this little bit of code will do what you need. I assume the variables in the dataset is organized as follows:
X1 to x560, y1 to y12. If it's not organized this way then do a Match files file=*/keep=... to order the variables as indicated.
So:
Vector x=x1 to x560/y=y1 to y12.
Compute #j=0.
Loop #i=1 to 560.
+  do if (not(missing(x(#i)))).
+     compute #j=#j+1.
+     compute y(#j)=x(#i).
+  end if.
End loop.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of pabstnjazz
Sent: Tuesday, August 11, 2015 9:48 AM
To: [hidden email]
Subject: create new vars from a range of existing vars based on non-missing

Dear List,

I have a scale comprised of 12 items, which I would like to examine more closely. My problem is that the formulation of the items is based on answers earlier in the questionnaire (a choice of 3 groups out of 16), so that the data for these 12 items is represented by 560 variables (the items ask for perceived similarity between the groups that were chosen before, so there are as many variables as hypothetically possible combinations of group pairs times the number of scale items). Every respondent has 12 valid values within these 560 variables, the rest are missing.

Is there a possibility to tell SPSS (v22) to "transport" the values of the
12 valid variables into 12 new variables? For example, transport the first value that is not missing within a defined range of variables (e.g., v_1 to
v_560) to v_1new, the second one to v_2new, and so forth?

Theoretically, I know which values are valid for every respondent, based on his or her answers to the item that determines the formulation of the mentioned 12 item scale. Thus, I could create 12 new variables and tell SPSS to fill in the respective values. For example, if a person chose groups 1, 4, and 15, he or she will also have answered variables v_12, v_28, v_74, v_78, v_129, v_222, v_322, v_432, v_454, v_500, v_544, v_568. But it would take me a couple of days, if not longer, only typing if- statements for these operations, because the 12 variables that will have been answered can only be identified unequivocally when I know which 3 groups were chosen, which means 580 (i.e. possible chosen group scenarios) if-statements for every one of the twelve items (I'm not entirely sure about this; I hope it's possible to fill in the 12 variables at once for every possible group scenario).

Also, I am pretty fixated at creating 12 new variables to analyse the scale's properties. Do you see another possibility to describe the characteristics of my scale? I have tried to describe my problem as concisely as possible. If you need more information, please feel free to ask. I will be very grateful for any hints in the right direction.

Kind regards,
Jan





--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/create-new-vars-from-a-range-of-existing-vars-based-on-non-missing-tp5730420.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: create new vars from a range of existing vars based on non-missing

pabstnjazz
Thank you very much for the quick response. I'll try it and let you know about the result.
Reply | Threaded
Open this post in threaded view
|

Re: create new vars from a range of existing vars based on non-missing

pabstnjazz
Everything worked! I am impressed and grateful!
Thank you again,
Jan
Reply | Threaded
Open this post in threaded view
|

Re: create new vars from a range of existing vars based on non-missing

David Marso
Administrator
In reply to this post by Maguin, Eugene
Adding a little extra (record the vector location where the item was found).
Since the original worked I assume the variables y1 TO y12 were already existing in the data file.

VECTOR x=x1 to x560/y=y1 to y12 /loc(12).
COMPUTE #j=0.
LOOP #i=1 TO 560.
+  DO IF (NOT (MISSING(x(#i)))).
+     COMPUTE #j=#j+1.
+     COMPUTE y(#j)=x(#i).
+     COMPUTE loc(#j)=#i.
+  END IF.
END LOOP.


Maguin, Eugene wrote
I think (not sure) that this little bit of code will do what you need. I assume the variables in the dataset is organized as follows:
X1 to x560, y1 to y12. If it's not organized this way then do a Match files file=*/keep=... to order the variables as indicated.
So:
Vector x=x1 to x560/y=y1 to y12.
Compute #j=0.
Loop #i=1 to 560.
+  do if (not(missing(x(#i)))).
+     compute #j=#j+1.
+     compute y(#j)=x(#i).
+  end if.
End loop.

Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of pabstnjazz
Sent: Tuesday, August 11, 2015 9:48 AM
To: [hidden email]
Subject: create new vars from a range of existing vars based on non-missing

Dear List,

I have a scale comprised of 12 items, which I would like to examine more closely. My problem is that the formulation of the items is based on answers earlier in the questionnaire (a choice of 3 groups out of 16), so that the data for these 12 items is represented by 560 variables (the items ask for perceived similarity between the groups that were chosen before, so there are as many variables as hypothetically possible combinations of group pairs times the number of scale items). Every respondent has 12 valid values within these 560 variables, the rest are missing.

Is there a possibility to tell SPSS (v22) to "transport" the values of the
12 valid variables into 12 new variables? For example, transport the first value that is not missing within a defined range of variables (e.g., v_1 to
v_560) to v_1new, the second one to v_2new, and so forth?

Theoretically, I know which values are valid for every respondent, based on his or her answers to the item that determines the formulation of the mentioned 12 item scale. Thus, I could create 12 new variables and tell SPSS to fill in the respective values. For example, if a person chose groups 1, 4, and 15, he or she will also have answered variables v_12, v_28, v_74, v_78, v_129, v_222, v_322, v_432, v_454, v_500, v_544, v_568. But it would take me a couple of days, if not longer, only typing if- statements for these operations, because the 12 variables that will have been answered can only be identified unequivocally when I know which 3 groups were chosen, which means 580 (i.e. possible chosen group scenarios) if-statements for every one of the twelve items (I'm not entirely sure about this; I hope it's possible to fill in the 12 variables at once for every possible group scenario).

Also, I am pretty fixated at creating 12 new variables to analyse the scale's properties. Do you see another possibility to describe the characteristics of my scale? I have tried to describe my problem as concisely as possible. If you need more information, please feel free to ask. I will be very grateful for any hints in the right direction.

Kind regards,
Jan





--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/create-new-vars-from-a-range-of-existing-vars-based-on-non-missing-tp5730420.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"