Permutations of binary variable

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

fboehlandt
Posts: 83
Joined: Thu Apr 15, 2010 3:54 am

Permutations of binary variable

Postby fboehlandt » Wed May 01, 2013 9:36 am

Hi,
I am looking for a way to create permutations of a binary variable for different n. Assuming n=3:

0 0 0
1 0 0
0 1 0
0 0 1
1 1 0
0 1 1
1 0 1
1 1 1

Does anybody have a code snippet that could be of use?
Many thanks in advance

fboehlandt
Posts: 83
Joined: Thu Apr 15, 2010 3:54 am

Re: Permutations of binary variable

Postby fboehlandt » Fri May 03, 2013 3:50 am

I have come up with this quickshot solution. Should work for other permutations as well with a little adaptation. Only drawback is that the permutations may not be in the desired order. Worked for my purposes though

Code: Select all

!nvar = 4 table(!nvar^2,!nvar) testtable !bin = 1 !s = !nvar ^ 2 for !j = 1 to !nvar !s = !s / 2 for !i = 1 to !nvar ^ 2 if (!i - 1) / !s = @round((!i - 1) / !s) Then !bin = @abs(1 - !bin) testtable(!i, !j) = !bin else testtable(!i, !j) = !bin endif next next


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests