Page 1 of 1

Basic Combination Question

Posted: Sat Feb 22, 2014 8:51 am
by CharlieEVIEWS
Dear all, a similar albeit noticably different question was asked last month (http://forums.eviews.com/viewtopic.php?f=5&t=9399) about a combining N objects. I am looking to create all unique combinations of objects 1,...,N as groups. Below is an illustrative example:

Code: Select all

wfcreate u 1 series a1 = nrnd series a2 = nrnd series a3 = nrnd series a4 = nrnd !totalnumber= 4 'number of series to be combined - N - see note below for !i = 1 to !totalnumber group group_{!i} a{!i} for !j = 1 to !totalnumber group group_{!i}_{!j} group_{!i} a{!j} for !k = 1 to !totalnumber group group_{!i}_{!j}_{!k} group_{!i}_{!j} a{!k} for !z = 1 to !totalnumber group group_{!i}_{!j}_{!k}_{!z} group_{!i}_{!j}_{!k} a{!z} next next next next
1.) While the example creates all possible combinations, most of them are not unique. For example, group_1_1 or group_2_2_2_2 should not exist. In addition, group_2_4 and group_4_2 are identical in their content.

2.) Is there a way to generalize the code so it is independent of the 'totalnumber', other than the replacement variable in the pre-amble?

3.) Importantly, I am unable to think of a way to name/rename the groups in a consistent manner. Ideally, I would really like them to be ordered something like group_1, group_2, group_3,.... group_{N(!)/(k(!)(N-k)(!))} or similar. I tried to freeze each group in the hope that EViews might output something like table01 table02 table03 which could be renamed appropriately, but to no avail

Any inspiration or ideas on any of the above would be hugely appreciated, as always! I am pretty sure 1.) can be accomplished somehow with if's, and I think the whole thing can be done in two for loops? But I cannot quite figure out how...

Charlie

Re: Basic Combination Question

Posted: Wed Feb 26, 2014 4:34 am
by CharlieEVIEWS
I guess the question is actually is about writing a routine to do something similar to the combinat::powerset(S) command in Matlab. I've worked on the problem a little further, but I'm still missing a couple of key parts (while/ifs) which I can't figure out, so if anyone has any insights that would be most helpful!

Re: Basic Combination Question

Posted: Mon Mar 03, 2014 3:02 pm
by CharlieEVIEWS
Without being able to generate user defined functions, I'm finding this quite tricky. I thought I had achieved it (at least for a region around !K, cannot think of how to generalize it without a function), with:

Code: Select all

!K = 5 'The only replacement: !K. This is the number of elements in the masterset wfcreate(wf=powersets) u 1 for !z = 1 to !K genr a!z = nrnd next !w=1 for !p = 1 to !K group group!w a!p !w=!w+1 for !q = !p+1 to !K group group!w group!p a!q !w=!w+1 for !r = !q+1 to !K group group!w group!p a!r !w=!w+1 if !r <!K then for !s = !r+1 to !K group group!w group!p a!s !w=!w+1 if !s<!K then for !t = !s+1 to !K group group!w group!p a!t !w=!w+1 next endif next endif next next next
which generates the right number of sets (groups) in this case, which is (2^!K)-1, but it is failing in the concatenation of groups.... suggestions most valuable!