Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inversion of a matrix

    Hello,
    I am only beginning with Stata and I am currently trying to invert a (256x256) matrix. This matrix is the result of the multiplication of a vector of residuals by the transposed of the same vector. Hence, this matrix is symmetric. However, when using the usual command:
    mat omegainv = inv(omega)
    stata tells me "matrix has missing values". I don't see where some values are missing.
    I also tried the code
    mat omegainv = invsym(omega)
    but here, Stata generates a (256x256) matrix only filled with 0, which is not what I expected.

    Has anyone already had this problem or knows how I can invert my matrix?

    Thanks a lot for your help
    Best, Quentin

  • #2
    Take the case when you have 2 observations, and your residuals are E1, E2.

    (E1 E2)'*(E1 E2) =

    (E1*E1 E1*E2)
    (E2*E1 E2*E2)

    Now the determinant is det = E1*E1*E2*E2 - E1*E2*E1*E2 = 0

    Therefore your matrix is singlular, not invertible.

    Comment


    • #3
      Therefore nobody can tell you how to invert your matrix because your matrix is non invertible.

      Now why one command in Stata says missing values, and the other command says zeros, is an interesting questions for Stata Corp.

      Here is a replication of this duality reported by OP.

      Code:
      . sysuse auto
      (1978 automobile data)
      
      . keep in 1/7
      (67 observations deleted)
      
      . qui reg price head mpg
      
      . predict e, resid
      
      . mkmat e, mat(E)
      
      . matlist E*E'
      
                   |        r1         r2         r3         r4         r5         r6         r7 
      -------------+-----------------------------------------------------------------------------
                r1 |  252.6552                                                                   
                r2 |  11783.19   549537.3                                                        
                r3 |  9502.342   443164.6   357382.3                                             
                r4 |  13732.92   640467.9     516494   746444.6                                  
                r5 | -21227.25  -989983.9    -798355   -1153794    1783443                       
                r6 |  754.1939   35173.65   28365.17   40993.75  -63364.85   2251.323            
                r7 | -14798.05  -690142.7  -556553.4    -804339    1243283  -44173.24   866723.7 
      
      . matlist invsym(E*E')
      
                   |        r1         r2         r3         r4         r5         r6         r7 
      -------------+-----------------------------------------------------------------------------
                r1 |         0                                                                   
                r2 |         0          0                                                        
                r3 |         0          0          0                                             
                r4 |         0          0          0          0                                  
                r5 |         0          0          0          0   5.61e-07                       
                r6 |         0          0          0          0          0          0            
                r7 |         0          0          0          0          0          0          0 
      
      . matlist inv(E*E')
      matrix has missing values
      r(504);
      
      .

      Comment


      • #4
        Dear M. Kolev,
        Thanks a lot for your answer. I should have tought about it. I must have a big problem of understanding of the formula I'm trying to use. Here is what our professor gave us (screenshot). To obtaind BetaFGLS, I need to invert Omega, but given your previous answer, Omega can't be invertible. So, how can I move to BetaFGLS? Or do I misunderstand the formula?
        Sorry for bothering you with things that must be so easy for you and thanks a lot in advance,
        Best,
        Quentin

        Click image for larger version

Name:	Capture d’écran 2022-04-29 122237.png
Views:	1
Size:	90.1 KB
ID:	1662154

        Comment


        • #5
          The formulae that you are displaying are for a different situation: You have panel data with i=1,2,..N panels, and your Vi are vectors of say T observations within the panel.

          To implement the formulae you are showing you need to do what we did above for each panel separately, average these resulting matrices over N, and invert the resulting averaged matrix.

          Programming this from scratch in Stata is a bit of a pain.

          There is a preprogrammed estimator that implements this procedure that is called -xtgls-.

          And if you need robust standard errors after this, there is a postestimation command that I wrote -xtglsr-.

          Originally posted by Quentin Richard View Post
          Dear M. Kolev,
          Thanks a lot for your answer. I should have tought about it. I must have a big problem of understanding of the formula I'm trying to use. Here is what our professor gave us (screenshot). To obtaind BetaFGLS, I need to invert Omega, but given your previous answer, Omega can't be invertible. So, how can I move to BetaFGLS? Or do I misunderstand the formula?
          Sorry for bothering you with things that must be so easy for you and thanks a lot in advance,
          Best,
          Quentin

          [ATTACH=CONFIG]n1662154[/ATTACH]

          Comment


          • #6
            Dear M. Kolev,
            Thanks, I got it. The professor explicitly asks us to do implement it manually. I'll try and if I fail, I'll use the codes you propose.
            Thank you again for your help,
            Best,
            Quentin

            Comment


            • #7
              Do come back and report the solutions after your professor and the smartest student in your class show you how to do it manually.

              The only approach that comes to me right now is to calculate this by brute force matrix operations. If you want to try this route, look through your lecture notes for an equivalent expression of what you showed above which does not involve summations. The expression has to involve a big X matrix that assembles in a particular way the individual Xi matrices, a big Y matrix that assembles in a particular way the individual Yi vectors, and a big block diagonal Omega matrix, which has on the main diagonal the Omega_i = Vi*Vi' matrices.

              Originally posted by Quentin Richard View Post
              Dear M. Kolev,
              Thanks, I got it. The professor explicitly asks us to do implement it manually. I'll try and if I fail, I'll use the codes you propose.
              Thank you again for your help,
              Best,
              Quentin

              Comment


              • #8
                Dear M. Kolev,
                Thank you for your proposal. I'll keep you informed when I receive the solutions, probably on Friday.
                Best,
                Quentin

                Comment

                Working...
                X