Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: MATA all combinations / pairs of a row


From   Sebastian Eppner <eppner@uni-potsdam.de>
To   statalist@hsphsun2.harvard.edu
Subject   st: MATA all combinations / pairs of a row
Date   Wed, 5 Oct 2011 23:08:14 +0200

Hi,
I have N elements. In this example N will be 3. But in my application
it will be usually around 7, going up to 20 in some cases…

Each element can be either 1 or 0. My basic matrix has all 2^N, here
2^3 permutations of the elements:

BASIC = ( 1,1,1) \ (1,1,0) \ (1,0,1) \ (0,1,1) \ (0,0,1) \ (0,1,0) \
(1,0,0) \(0,0,0)

The elements have 2 “properties” , PROP1 and PROP2  each, stored in 2
rows of another matrix, for example:

PROPERTIES = (1.4,4.6,8.1) \ (0.2, 0.4, 0.4)

Every row in BASIC resembles a unique combination of the elements.
What I want to do, is to calculate some indicators for every
combination, using the Properties of the elements.

An easy example would be to calculate the total sum of PROP1 for each
combination. I just need to multiply the “diagonalized” first row of
the PROPERTIES Matrix with the BASIC Matrix and then calculate the
rowsum of this resulting matrix.


What I want to do now is more complex and I am really stuck. The
indicator I want to calculate now is the following:

For each row/combination in BASIC  I need to  find all PAIRS of Ones
that are contained in the combination. For any pair, I need to
multiply:

PROP1 of Element1 * PROP1 of Element2  * abs(PROP2 of Element1-PROP2
of ELEMENT2)

It is the sum of all PAIRS that I need to know for every row….


Of course, not every row has PAIRS in it… all rows with only 1 One
have no pairs, so the result for these rows should be 0 (or missing, I
don’t care).

Also, many rows (those with only 2 Ones) have only a single Pair…

In my Example with 3 elements, only the first row sums up more than
one (3) Pair(s)….


I am looking for a way to solve this problem by not using loops… and
as much matrix algorithms as possible. Since I have a lot of BASIC
Matrices with more elements than 3… I guess the whole thing would be
very very time consuming if I started smth with loops… Maybe there is
no way to get rid of any loop… any idea would be very welcome (even
some, with a little looping).

Thanks a lot for any help!

Sebastian

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index