Basic Combination Question
Posted: Sat Feb 22, 2014 8:51 am
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:
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
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
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