0

I'm trying to get inverse matrix with inv() function. Excel function is working fine but I can't get it from Stata 11 and Stata 12 version

matrix A = (0,0,553959,18071,0,0,86985,0,0,0\0,0,13752,1986661,0,0,14178,0,0,0\245764,55172,0,0,0,0,210238,15835,0,174155\135950,1217897,0,0,211554,0,348453,197592,424893,704246\0,0,40442,171113,0,0,0,0,0,0\277015,720994,0,0,0,0,0,0,0,0\0,0,0,0,0,989861,121720,67779,0,58624\286,20529,34840,90896,0,8147,157021,265924,51955,4187\0,0,0,0,0,0,299389,86656,0,90804\0,0,58171,973844,0,0,0,0,0,0)
matrix list A
matrix D = inv(A)*A
matrix list D

I get:

    D[10,10]
             c1          c2          c3          c4          c5          c6          c7          c8          c9         c10
 c1   .99815163   -.0007439          24         256  -4.441e-18   .02180544   .63042827   .71306993   .13905754   .72740125
 c2   .00071017   1.0002858         -64        -640   1.978e-17  -.00837793   1.0656752  -.27397047  -.05342766  -.27947675
 c3   2.008e-20   8.082e-21    2.143632   20.313752           0  -2.369e-19   .08155506  -7.747e-18  -1.511e-18  -2.800e-19
 c4   7.748e-22   3.118e-22   .04412596   1.7837869           0  -9.141e-21   .00314672  -2.989e-19  -5.829e-20  -1.080e-20
 c5  -.03648975  -.01468572         512        2048           1     .430473   13.357737   14.077098   2.7452099   14.360021
 c6     .000033   .00001328      -1.125         -12           0    .9996107  -.09016952  -.01273068  -.00248264  -.01298654
 c7  -1.280e-19  -5.153e-20   -7.292322   -129.5298           0   1.511e-18   .47996753   4.940e-17   9.633e-18   1.785e-18
 c8  -.00276051    -.001111          32         512           0   .03256598   3.1088352   2.0649553   .20767957   1.0863588
 c9   .01364134   .00549012           0       -1024           0   -.1609282  -9.7734934  -5.2625881  -.02627036  -5.3683558
c10   .00263441   .00106025           0        -128           0  -.03107834  -1.6240499  -1.0163072   -.1981926  -.03673303

But I think it should be:

1   0   0   0   0   0   0   0   0   0
0   1   0   0   0   0   0   0   0   0
14  -8  1   -9,42932E-17    -64 1,00614E-16 -1,73472E-18    0   1,33227E-15 32
0   -32 -5,55112E-17    1   0   1,11022E-16 0   0   0   -128
0,021597505 -0,210228064    0   0   0,788571331 4,27485E-20 2,13743E-20 0   5,47181E-18 0,788571331
0   0   0   0   0   1   0   0   0   0
0   0   0   0   -16 -8,67362E-19    1   0   0   0
3,5 -1,75   6,93889E-18 -2,7765E-19 -128    1,38778E-17 0   1   2,22045E-16 35
0   0   0   0   0   0   0   0   1   0
-0,007446191    -0,112499947    0   0   1,604924249 8,70031E-20 4,35016E-20 0   1,11364E-17 1,604924249
Nick Cox
  • 35,529
  • 6
  • 31
  • 47
Nurlan
  • 505
  • 1
  • 4
  • 11
  • What is the expectation here, that Stata should match Excel's numerics? – Nick Cox Oct 12 '15 at 07:44
  • I have excel example of matrix inverse of givven data : 0,0,553959,18071,0,0,86985,0,0,0\0,0,13752,1986661,0,0,14178,0,0,0\245764,55172,0,0,0,0,210238,15835,0,174155\135950,1217897,0,0,211554,0,348453,197592,424893,704246\0,0,40442,171113,0,0,0,0,0,0\277015,720994,0,0,0,0,0,0,0,0\0,0,0,0,0,989861,121720,67779,0,58624\286,20529,34840,90896,0,8147,157021,265924,51955,4187\0,0,0,0,0,0,299389,86656,0,90804\0,0,58171,973844,0,0,0,0,0,0 – Nurlan Oct 12 '15 at 08:36
  • And result is like I wrote below – Nurlan Oct 12 '15 at 08:37
  • 2
    I don't see here an answer to my query. If you are concerned about numerical precision, and you don't have independent evidence for what is demonstrably correct, then you need to see which program is "odd one out" and no comparison of two programs can do that. Try R, MATLAB, etc. as well. – Nick Cox Oct 12 '15 at 09:07

1 Answers1

1

I believe the problem is your matrix is ill-conditioned, i.e. almost singular.

If you try to compute the inverse within Mata (Stata's matrix programming language), the result is:

: Ainv = luinv(A)

: Ainv
[symmetric]
         1    2    3    4    5    6    7    8    9   10
     +---------------------------------------------------+
   1 |   .                                               |
   2 |   .    .                                          |
   3 |   .    .    .                                     |
   4 |   .    .    .    .                                |
   5 |   .    .    .    .    .                           |
   6 |   .    .    .    .    .    .                      |
   7 |   .    .    .    .    .    .    .                 |
   8 |   .    .    .    .    .    .    .    .            |
   9 |   .    .    .    .    .    .    .    .    .       |
  10 |   .    .    .    .    .    .    .    .    .    .  |
     +---------------------------------------------------+

Couple that with:

If you use these functions with a singular matrix, returned will be a matrix of missing values. The determination of singularity is made relative to tol. See Tolerance under Remarks in [M-5] lusolve() for details.

Source: help mf_luinv.

Checking the condition number, we see it is very high, confirming the ill-condition:

: C = cond(A)

: C
  7.47519e+17

Numerical methods vary, but for a matrix like this, you can expect large inaccuracies. See help mf_lusolve##remarks3 as indicated above.

Roberto Ferrer
  • 11,024
  • 1
  • 21
  • 23