Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Matrix problem


From   Eric Cahuzac <[email protected]>
To   [email protected]
Subject   st: Matrix problem
Date   Mon, 21 Jul 2003 19:15:52 +0200

Hi
Does anyone know how to solve this pb
Here is my data set (a sample)

    +----------------+
    | v1    v2    v3 |
    |----------------|
 1. |  2   100   101 |
 2. |  2   100   102 |
 3. |  2   100   104 |
 4. |  3   100   105 |
 5. |  2   100   106 |
    |----------------|
 6. |  3   100   125 |
 7. |  2   100   131 |
 8. |  2   100   138 |
 9. |  2   101   105 |
10. |  2   101   106 |
    |----------------|
11. |  3   101   125 |
12. |  2   101   131 |
13. |  2   102   104 |
14. |  2   102   105 |
15. |  2   102   106 |
    +----------------+

a table of v2 v3, missing gives that

----------------------------------------------------------
         |                       v3
      v2 |  101   102   104   105   106   125   131   138
----------+-----------------------------------------------
     100 |    1     1     1     1     1     1     1     1
     101 |    .     .     .     1     1     1     1     .
     102 |    .     .     1     1     1     .     .     .
----------------------------------------------------------

I want to obtain a matrix:

A[3,8]
    101  102  104  105  106  125  131  138
100    .    .    .    .    .    .    .    .
101    .    .    .    .    .    .    .    .
102    .    .    .    .    .    .    .    .

where dots are replaced by corresponding values of v1

I try something like the following:

vallist v2, g(v2)
qui tab v2
global nbli=r(r)
vallist v3, g(v3)
qui tab v3
global nbco=r(r)

matrix A=J($nbli,$nbco,.)
mat rown A = $v2
mat coln A = $v3

local i = 0
local j = 0
foreach k of num $v2 {
local i = `i' + 1
foreach m of num $v3 {
local j = `j' + 1
matrix A[`i',`j']=????????
}
local j = 0
}

Do you have any idea on how to cope with this problem?
Thank you very much!
Eric





*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index