Announcement

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

  • matrix var nov with zeros for base dummy level

    Dear friends from the State community :
    I estimated a model with dummy variables but when I take a look at the variance covariance matrix it has columns/rows with only zero values, corresponding to the baseline of the dummy variables. Hence the matrix is non-invertible.
    For the sake of simplicity, let's consider a simple regression "reg y x i.gov" , with "gov" a dummy variable taking the values 1, 2 and 3. Of course the regression output doesn't include the first level of that dummy variable BUT when I see the VarCov matrix there is one column and one row for this base level (zeros), hence it is not invertible. The same happens if I consider a dummy variable taking values 0 and 1. I attach the regression output and the matrix. Can anyone lend me a hand? Many thanks..

    Click image for larger version

Name:	Screen Shot 2019-10-29 at 19.24.34.png
Views:	1
Size:	62.4 KB
ID:	1522376




    Attached Files

  • #2
    Juan:
    I think you should take a look at -estat vce-:
    Code:
    . sysuse auto.dta
    (1978 Automobile Data)
    
    . reg price i.foreign mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     14.07
           Model |   180261702         2  90130850.8   Prob > F        =    0.0000
        Residual |   454803695        71  6405685.84   R-squared       =    0.2838
    -------------+----------------------------------   Adj R-squared   =    0.2637
           Total |   635065396        73  8699525.97   Root MSE        =    2530.9
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
         foreign |
        Foreign  |   1767.292    700.158     2.52   0.014     371.2169    3163.368
             mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
           _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
    ------------------------------------------------------------------------------
    
    . mat list e(V)
    
    symmetric e(V)[4,4]
                        0b.          1.                      
                   foreign     foreign         mpg       _cons
    0b.foreign           0
     1.foreign           0   490221.18
           mpg           0  -15339.746   3101.5675
         _cons           0   180953.69  -61494.541   1342433.8
    
    . estat vce
    
    Covariance matrix of coefficients of regress model
    
                 |          1.                      
            e(V) |    foreign         mpg       _cons
    -------------+------------------------------------
       1.foreign |  490221.18                        
             mpg | -15339.746   3101.5675            
           _cons |  180953.69  -61494.541   1342433.8
    
    .
    Last edited by Carlo Lazzaro; 29 Oct 2019, 02:41.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      It worked !!! thank you very much Carlo... best regards.

      Comment


      • #4
        I am sorry Carlo, I responded without taking a deeper look at this. It worked in the sense I could see the matrix without the column and row with zeros but the matrix as it is named, e(V), is still the original one (with the zero values column and row) , hence when I try to invert it , typing matrix inv=inv(e(V)) , the same problem appears... is there any way to tell state to consider the matrix without these column and row when estimating the inverse matrix? Many thanks, Juan

        Comment


        • #5
          Juan:
          admittedly, I've never challenged myself with matrix inversion.
          Perhaps this task can be easily performed with -mata- (minor surgery to kick off the 0 column and row included).
          Sorry I cannot be more helpful.
          Kind regards,
          Carlo
          (Stata 18.0 SE)

          Comment


          • #6
            I strongly suspect we have a xy-problem (https://en.wikipedia.org/wiki/XY_problem): You think you need to invert that matrix to solve your problem, but in reality there is probably a much easier, saver, and quicker solution. The baseline coefficients and variables omitted due to multicolinearity, etc. are all labeled, and there are tools in Stata that allow you to use that information, but I think you would benefit more if we take a step back and look at what your real problem is, so we can solve that. So can you tell us why you think you need to invert that matrix?
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Thanks Carlo. Thanks Maarten. I think I can save the e(V) matrix using the svmat command and then export it to a csv file. I'll try following this. Maarten: I still want to explain what I am doing because there is another doubt that I posted yesterday without getting any response so maybe here.... I work with multi output distance functions and Stochastic Frontier Analysis (the regression I used to illustrate this in my first post has nothing to do with my model, but that is not relevant). In this literature violations of the monotonicity condition are rather common and there are some methods to fix the issue. One of them involves using a minimum distance estimator, minimising the following expression:
              Br = arg min(Br - Bu)*IM*(Br - Bu) subject to a linear restriction, which I don't write here. IM is the inverse of the var/cov matrix and Bu is a known vector of coefficients (from the unrestricted model). Br is the (incognita) coefficients vector that minimises that function and guarantees the restriction is fulfilled.
              That is why I need this. By the way, if any of you know how to minimise a non-linear function subject to a linear restriction that'd be nice. I think it can be done in Mata but I am not familiarised with that (I post this other question yesterday but haven't got any response). Thanks again.

              Comment


              • #8
                Ok, that sound like a legitimate reason. The easiest way to get the inverse is to just use invsym() instead of inv(). Especially if you get the Br and Bu matrices from e(b), so you won't have to bother with the omitted variables in all three matrices. It is actually a good idea to use invsym() whenever possible anyhow. Inverting a matrix is a numerically tricky thing, so if you know the matrix is symmetric, then you should use that info.

                If you want to remove the omitted variables before you do that you can:

                Code:
                // open example dataset
                sysuse auto
                
                // estimate a regression with a reference category
                reg price i.rep78
                
                // find out which parameters are omitted
                _ms_omit_info e(b)
                
                // enter Mata
                mata
                
                // load the matrices in Mata
                v = st_matrix("e(V)")
                incl = st_matrix("r(omit)"):== 0
                
                // remove the omitted variables
                v = select(v, incl)
                v = select(v, incl')
                
                // move the matrix back to Stata
                st_matrix("v", v)
                
                //make it pretty by attaching row and column names
                names = st_matrixrowstripe("e(V)")
                names = select(names, incl')
                st_matrixrowstripe("v",names)
                st_matrixcolstripe("v",names)
                
                end
                
                // matrix with omitted variables removed
                matlist v
                
                //original matrix
                matlist e(V)
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment


                • #9
                  thanks Maarten. This is really very generous of you. All the best, Juan

                  Comment

                  Working...
                  X