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
Permutations of binary variable
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
fboehlandt
- Posts: 83
- Joined: Thu Apr 15, 2010 3:54 am
Re: Permutations of binary variable
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
Who is online
Users browsing this forum: No registered users and 2 guests
