|
Hi All,
we have to fulfill the task to build all combinations of dichotomous variables. The amout of variables varies from dataset to dataset - cause we are doing it in many countries. We put the interesting variables in a SPSS vector looking like this: Vector = age employment sex some other variables ... (= v1 v2 v3 v4 v5 v6). What we are looking for are all combinations of 2, 3, 4, 5 and 6 variables, like this V1 + v2 V1 + v3 V1 + v4 V1 + v5 V1 + v6 V2 + v3 V2 + v4 V2 + v5 V2 + v6 V3 + v4 V3 + v5 V3 + v6 and so on. We need the same with the combinations of 3 like V1 + v2 + v3 V1 + v2 + v4 V1 + v2 + v5 V1 + v2 + v6 V2 + v3 + v4 V2 + v3 + v5 V2 + v3 + v6 V3 + v4 + v5 V3 + v4 + v6 and so on. The same with the combinations of 4 and 5 and 6. The double should be left out, e.g. the combination v2 + v1 is not needed because it is the same as v1 + v2. We had a look at the site of Raynald Levesque but did not find a syntax doing exactly this. Is there any syntax that can handle this problem? Best regards Georg Maubach Research Manager |
|
Does this do what you want?
DATA LIST FREE /v1 v2 v3 v4 v5. BEGIN DATA 1 2 3 4 5 10 20 30 40 50 END DATA. DO REPEAT x = v2 v3 v4 v5 /y = newv1v2 newv1v3 newv1v4 newv1v5. COMPUTE y = v1 + x. END REPEAT . EXECUTE. You can add other DO REPEAT structures to get the other combinations you want. (It looks like you will need a lot of the DO REPEAT structures...) --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Georg Maubach Sent: Friday, July 27, 2007 11:10 AM To: [hidden email] Subject: All combinations of variables Hi All, we have to fulfill the task to build all combinations of dichotomous variables. The amout of variables varies from dataset to dataset - cause we are doing it in many countries. We put the interesting variables in a SPSS vector looking like this: Vector = age employment sex some other variables ... (= v1 v2 v3 v4 v5 v6). What we are looking for are all combinations of 2, 3, 4, 5 and 6 variables, like this V1 + v2 V1 + v3 V1 + v4 V1 + v5 V1 + v6 V2 + v3 V2 + v4 V2 + v5 V2 + v6 V3 + v4 V3 + v5 V3 + v6 and so on. We need the same with the combinations of 3 like V1 + v2 + v3 V1 + v2 + v4 V1 + v2 + v5 V1 + v2 + v6 V2 + v3 + v4 V2 + v3 + v5 V2 + v3 + v6 V3 + v4 + v5 V3 + v4 + v6 and so on. The same with the combinations of 4 and 5 and 6. The double should be left out, e.g. the combination v2 + v1 is not needed because it is the same as v1 + v2. We had a look at the site of Raynald Levesque but did not find a syntax doing exactly this. Is there any syntax that can handle this problem? Best regards Georg Maubach Research Manager |
|
In reply to this post by Georg Maubach
Georg,
I don't know whether you got a good reply or not but here is my idea. For this all to work, your data are going to have to be structured in a very specific way. My preference is to use string variables for making combinations of variables because the string variables display better. You may prefer numeric. I assume v1 to v6 all have only single character values. String v12 v13 v14 v15 v16 v22 v24 v25 v26 v34 v35 v36 v45 v46 v56(a2). Vector twos=v12 to v56. Vector in=v1 to v6. Compute #ij=0. Loop #i=1 to 5. Loop #j=#i+1 to 6. + compute #ij=#ij+1. + compute twos(#ij)=concat(string(in(#i),f1.0),string(in(#j),f1.0)). End loop. End loop. I think that you can adapt the method to combinations of 3, 4 or 5 variables. If not, repost back and I or somebody else can offer an idea. Gene Maguin |
|
In reply to this post by Georg Maubach
Georg -
Did Jim Marks's answer, or Gene Maguin's, or any other one, solve your problem? At 12:09 PM 7/27/2007, Georg Maubach wrote: >we have build all combinations of dichotomous >variables. The amout of variables varies from >dataset to dataset - cause we are doing it in many countries. > >We put the interesting variables in a SPSS vector looking like this: > >Vector = age employment sex some other variables >... (= v1 v2 v3 v4 v5 v6). > >What we are looking for are all combinations of >2, 3, 4, 5 and 6 variables, like this > >V1 + v2 >V1 + v3 >V1 + v4 >V1 + v5 >V1 + v6 OK, here's where I get lost. When you write "V1 + V2", is "+" arithmetic addition, or something else? Does it mean, perhaps, "V1 and V2 are 1, and all the other variables are 0"? >We need the same with the combinations of 3 like >V1 + v2 + v3 Again, what do you mean, here? Anything like, "v1 and v2 and v3 are 1, and all the other variables are 0"? >We had a look at the site of Raynald Levesque >but did not find a syntax >doing exactly this. Is there any syntax that can handle this problem? If you do want to list all 2**n combinations of values for n dichotomous variables, solutions have been posted. Probably the most complete are, Date: Wed, 5 Jul 2006 16:51:07 -0400 From: Richard Ristow <[hidden email]> Subject: Re: Generating all posibble binary patterns for m variables To: [hidden email] Uses a macro within an INPUT PROGRAM. Works for any number of variables. Creates new variables, rather than setting values of existing ones. Date: Thu, 6 Jul 2006 09:22:34 +0200 From: Marta García-Granero <[hidden email]> Subject: Re: Generating all posibble binary patterns for m variables To: [hidden email] Same thread. An alternative solution, using MATRIX. |
|
I have a fairly large data set with several hundred variables. When I use
the menu system, I have to hunt through the list of variables, and that is difficult (I'm using ver. 12). I would love to have a "search" function to find variable names on demand in the list-- or at least to alphabetize the list. Is there any way to do that, in ver. 12, or in later versions? Bob Schacht Robert M. Schacht, Ph.D. <[hidden email]> Pacific Basin Rehabilitation Research & Training Center 1268 Young Street, Suite #204 Research Center, University of Hawaii Honolulu, HI 96814 |
|
Bob Schacht escribió:
> I have a fairly large data set with several hundred variables. When I use > the menu system, I have to hunt through the list of variables, and > that is > difficult (I'm using ver. 12). I would love to have a "search" > function to > find variable names on demand in the list-- or at least to alphabetize > the > list. Is there any way to do that, in ver. 12, or in later versions? Hi Bob Perhaps using Variable Sets (UTILITIES -> VARIABLE SETS) would help. When I have huge datasets (with a lot of variables, rather than a lot of cases) I organize variables by topic: demographic data, clinical data, response to surveys... Then I select the Variable set(s) (UTILITIES->USE VARIABLE SETS) I need for specific statistical analyses and the variables not needed are hidden in any dialog box. Not exactly what you needed but it's the only idea I can offer. To alphabetize the list: 1) Under EDIT->OPTIONS, you can choose the way the variables are list between "alphabetical" and "file". 2) If you want to sort the variables alphabetically in your file and keep then in ordered, then take a look at this code: http://www.spsstools.net/Syntax/LabelsAndVariableNames/SortVariableNamesByAlphaOrder_AnswerNet.txt HTH, Marta Garcia-Granero |
| Free forum by Nabble | Edit this page |
