Announcement

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

  • Variance Covariance Matrix of Sureg in Stata

    Hi everyone,

    I have a question about how to display the variance-covariance matrix for the residuals when using sureg in Stata. I know that corr option can give a correlation matrix, but what we want is a variance-covariance matrix and we wonder if anyone knows how to realize this in Stata?

    Thanks a lot!

  • #2
    If you mean the variance-covariance matrix of the estimators, you can see it with -estat vce-.

    Comment


    • #3
      Originally posted by Melody Brown View Post
      how to display the variance-covariance matrix for the residuals when using sureg in Stata.
      According to the help file for sureg it's among the list of objects that are ereturned: " e(Sigma) Sigma hat, covariance matrix of residuals".

      It seems accurate.

      .ÿ
      .ÿversionÿ17.0

      .ÿ
      .ÿclearÿ*

      .ÿ
      .ÿ//ÿseedem
      .ÿsetÿseedÿ565332290

      .ÿ
      .ÿtempnameÿCov

      .ÿmatrixÿdefineÿ`Cov'ÿ=ÿ100,ÿ-25ÿ\ÿ-25,ÿ50

      .ÿ
      .ÿquietlyÿdrawnormÿe1ÿe2,ÿdoubleÿcov(`Cov')ÿn(1000)

      .ÿ
      .ÿsuregÿ(e1ÿ)ÿ(e2ÿ)

      Seeminglyÿunrelatedÿregression
      ------------------------------------------------------------------------------
      EquationÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿÿÿParamsÿÿÿÿÿÿÿÿÿRMSEÿÿ"R-squared"ÿÿÿÿÿÿchi2ÿÿÿP>chi2
      ------------------------------------------------------------------------------
      e1ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1,000ÿÿÿÿÿÿÿÿ1ÿÿÿÿÿ10.17879ÿÿÿÿÿÿ0.0000ÿÿÿÿÿÿÿ0.04ÿÿÿ0.8348
      e2ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1,000ÿÿÿÿÿÿÿÿ1ÿÿÿÿÿ7.025012ÿÿÿÿÿÿ0.0000ÿÿÿÿÿÿÿ3.49ÿÿÿ0.0619
      ------------------------------------------------------------------------------

      ------------------------------------------------------------------------------
      ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
      -------------+----------------------------------------------------------------
      e1ÿÿÿÿÿÿÿÿÿÿÿ|
      ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.0671311ÿÿÿ.3218815ÿÿÿÿ-0.21ÿÿÿ0.835ÿÿÿÿ-.6980073ÿÿÿÿ.5637451
      -------------+----------------------------------------------------------------
      e2ÿÿÿÿÿÿÿÿÿÿÿ|
      ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.4147558ÿÿÿ.2221504ÿÿÿÿ-1.87ÿÿÿ0.062ÿÿÿÿ-.8501625ÿÿÿÿÿ.020651
      ------------------------------------------------------------------------------

      .ÿmatrixÿlistÿe(Sigma)

      symmetricÿe(Sigma)[2,2]
      ÿÿÿÿÿÿÿÿÿÿÿÿe1ÿÿÿÿÿÿÿÿÿÿe2
      e1ÿÿÿ103.60772
      e2ÿÿ-26.043198ÿÿÿ49.350798

      .ÿ
      .ÿexit

      endÿofÿdo-file


      .

      Comment


      • #4
        Originally posted by Joseph Coveney View Post
        According to the help file for sureg it's among the list of objects that are ereturned: " e(Sigma) Sigma hat, covariance matrix of residuals".

        It seems accurate.

        .ÿ
        .ÿversionÿ17.0

        .ÿ
        .ÿclearÿ*

        .ÿ
        .ÿ//ÿseedem
        .ÿsetÿseedÿ565332290

        .ÿ
        .ÿtempnameÿCov

        .ÿmatrixÿdefineÿ`Cov'ÿ=ÿ100,ÿ-25ÿ\ÿ-25,ÿ50

        .ÿ
        .ÿquietlyÿdrawnormÿe1ÿe2,ÿdoubleÿcov(`Cov')ÿn(1000)

        .ÿ
        .ÿsuregÿ(e1ÿ)ÿ(e2ÿ)

        Seeminglyÿunrelatedÿregression
        ------------------------------------------------------------------------------
        EquationÿÿÿÿÿÿÿÿÿÿÿÿÿObsÿÿÿParamsÿÿÿÿÿÿÿÿÿRMSEÿÿ"R-squared"ÿÿÿÿÿÿchi2ÿÿÿP>chi2
        ------------------------------------------------------------------------------
        e1ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1,000ÿÿÿÿÿÿÿÿ1ÿÿÿÿÿ10.17879ÿÿÿÿÿÿ0.0000ÿÿÿÿÿÿÿ0.04ÿÿÿ0.8348
        e2ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ1,000ÿÿÿÿÿÿÿÿ1ÿÿÿÿÿ7.025012ÿÿÿÿÿÿ0.0000ÿÿÿÿÿÿÿ3.49ÿÿÿ0.0619
        ------------------------------------------------------------------------------

        ------------------------------------------------------------------------------
        ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
        -------------+----------------------------------------------------------------
        e1ÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.0671311ÿÿÿ.3218815ÿÿÿÿ-0.21ÿÿÿ0.835ÿÿÿÿ-.6980073ÿÿÿÿ.5637451
        -------------+----------------------------------------------------------------
        e2ÿÿÿÿÿÿÿÿÿÿÿ|
        ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.4147558ÿÿÿ.2221504ÿÿÿÿ-1.87ÿÿÿ0.062ÿÿÿÿ-.8501625ÿÿÿÿÿ.020651
        ------------------------------------------------------------------------------

        .ÿmatrixÿlistÿe(Sigma)

        symmetricÿe(Sigma)[2,2]
        ÿÿÿÿÿÿÿÿÿÿÿÿe1ÿÿÿÿÿÿÿÿÿÿe2
        e1ÿÿÿ103.60772
        e2ÿÿ-26.043198ÿÿÿ49.350798

        .ÿ
        .ÿexit

        endÿofÿdo-file


        .
        Thanks a lot, Joseph! This is exactly what I want

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          If you mean the variance-covariance matrix of the estimators, you can see it with -estat vce-.
          Hi Clyde,

          Thank you very much for your reply. I'll check the command

          Comment


          • #6
            Originally posted by Melody Brown View Post
            Hi everyone,

            I have a question about how to display the variance-covariance matrix for the residuals when using sureg in Stata. I know that corr option can give a correlation matrix, but what we want is a variance-covariance matrix and we wonder if anyone knows how to realize this in Stata?

            Thanks a lot!
            Hi Clyde and Joseph,

            I have an additional question: I wonder for this e(Sigma) option can we add anything else to show the significance of the covariances between the residuals?

            Please let me know if you have any thoughts on this.

            Thanks

            Comment


            • #7
              Originally posted by Melody Brown View Post
              for this e(Sigma) option can we add anything else to show the significance of the covariances between the residuals?

              Please let me know if you have any thoughts on this.
              Not that I'm aware of, but then I don't use sureg.

              You can probably get at it by predicting the residuals for each equation and using something like pwcorr. It's illustrated below, along with a likelihood-ratio test of the same thing using sem to fit a covariance term for the residuals of the two equations.

              .ÿ
              .ÿversionÿ17.0

              .ÿ
              .ÿclearÿ*

              .ÿ
              .ÿquietlyÿsysuseÿauto

              .ÿ
              .ÿsuregÿ(mpgÿc.weight)ÿ(headroomÿc.length),ÿnoheader

              ------------------------------------------------------------------------------
              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
              -------------+----------------------------------------------------------------
              mpgÿÿÿÿÿÿÿÿÿÿ|
              ÿÿÿÿÿÿweightÿ|ÿÿÿ-.006009ÿÿÿ.0005108ÿÿÿ-11.76ÿÿÿ0.000ÿÿÿÿ-.0070102ÿÿÿ-.0050078
              ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ39.44121ÿÿÿ1.592028ÿÿÿÿ24.77ÿÿÿ0.000ÿÿÿÿÿ36.32089ÿÿÿÿ42.56153
              -------------+----------------------------------------------------------------
              headroomÿÿÿÿÿ|
              ÿÿÿÿÿÿlengthÿ|ÿÿÿ.0195919ÿÿÿ.0037825ÿÿÿÿÿ5.18ÿÿÿ0.000ÿÿÿÿÿ.0121783ÿÿÿÿ.0270055
              ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.6887166ÿÿÿ.7157624ÿÿÿÿ-0.96ÿÿÿ0.336ÿÿÿÿ-2.091585ÿÿÿÿ.7141519
              ------------------------------------------------------------------------------

              .ÿ
              .ÿ//ÿOneÿmethod,ÿquickÿandÿdirty,ÿperhaps
              .ÿpredictÿdoubleÿe_mpg,ÿresidualsÿeq(#1)

              .ÿpredictÿdoubleÿe_hea,ÿresidualsÿeq(#2)

              .ÿpwcorrÿe_*,ÿsig

              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿe_mpgÿÿÿÿe_hea
              -------------+------------------
              ÿÿÿÿÿÿÿe_mpgÿ|ÿÿÿ1.0000ÿ
              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
              ÿÿÿÿÿÿÿe_heaÿ|ÿÿ-0.0138ÿÿÿ1.0000ÿ
              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿ0.9071
              ÿÿÿÿÿÿÿÿÿÿÿÿÿ|

              .ÿ
              .ÿ//ÿAlternative,ÿmaybeÿmoreÿprincipled
              .ÿsemÿ(e_mpgÿ)ÿ(e_heaÿ),ÿ///
              >ÿÿÿÿÿÿÿÿÿnocnsreportÿnodescribeÿnofootnoteÿnolog

              StructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿ74
              Estimationÿmethod:ÿml

              Logÿlikelihoodÿ=ÿ-276.03339

              ---------------------------------------------------------------------------------
              ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿOIM
              ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿstd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
              ----------------+----------------------------------------------------------------
              ÿÿÿÿÿmean(e_mpg)|ÿÿÿ5.72e-14ÿÿÿ.3943236ÿÿÿÿÿ0.00ÿÿÿ1.000ÿÿÿÿÿÿ-.77286ÿÿÿÿÿÿ.77286
              ÿÿÿÿÿmean(e_hea)|ÿÿ-2.80e-14ÿÿÿ.0836526ÿÿÿÿ-0.00ÿÿÿ1.000ÿÿÿÿ-.1639561ÿÿÿÿ.1639561
              ----------------+----------------------------------------------------------------
              ÿÿÿÿÿÿvar(e_mpg)|ÿÿÿ11.50634ÿÿÿ1.891631ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ8.336823ÿÿÿÿ15.88086
              ÿÿÿÿÿÿvar(e_hea)|ÿÿÿ.5178342ÿÿÿ.0851314ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.3751924ÿÿÿÿÿ.714706
              ----------------+----------------------------------------------------------------
              cov(e_mpg,e_hea)|ÿÿ-.0336703ÿÿÿÿ.283785ÿÿÿÿ-0.12ÿÿÿ0.906ÿÿÿÿ-.5898787ÿÿÿÿ.5225381
              ---------------------------------------------------------------------------------

              .ÿestimatesÿstoreÿCovariance

              .ÿ
              .ÿquietlyÿsemÿ(e_mpgÿ)ÿ(e_heaÿ),ÿcovariance(e_mpg*e_hea@0)ÿ

              .ÿlrtestÿCovariance

              Likelihood-ratioÿtest
              Assumption:ÿ.ÿnestedÿwithinÿCovariance

              ÿLRÿchi2(1)ÿ=ÿÿÿ0.01
              Probÿ>ÿchi2ÿ=ÿ0.9055

              .ÿ
              .ÿexit

              endÿofÿdo-file


              .


              If you're that interested in some kind of null hypothesis significance test that the covariance of the residuals is exactly zero, then maybe fit a model using sem or gsem from the beginning.

              Comment


              • #8
                Originally posted by Joseph Coveney View Post
                Not that I'm aware of, but then I don't use sureg.

                You can probably get at it by predicting the residuals for each equation and using something like pwcorr. It's illustrated below, along with a likelihood-ratio test of the same thing using sem to fit a covariance term for the residuals of the two equations.

                .ÿ
                .ÿversionÿ17.0

                .ÿ
                .ÿclearÿ*

                .ÿ
                .ÿquietlyÿsysuseÿauto

                .ÿ
                .ÿsuregÿ(mpgÿc.weight)ÿ(headroomÿc.length),ÿnoheader

                ------------------------------------------------------------------------------
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿStd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                -------------+----------------------------------------------------------------
                mpgÿÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿweightÿ|ÿÿÿ-.006009ÿÿÿ.0005108ÿÿÿ-11.76ÿÿÿ0.000ÿÿÿÿ-.0070102ÿÿÿ-.0050078
                ÿÿÿÿÿÿÿ_consÿ|ÿÿÿ39.44121ÿÿÿ1.592028ÿÿÿÿ24.77ÿÿÿ0.000ÿÿÿÿÿ36.32089ÿÿÿÿ42.56153
                -------------+----------------------------------------------------------------
                headroomÿÿÿÿÿ|
                ÿÿÿÿÿÿlengthÿ|ÿÿÿ.0195919ÿÿÿ.0037825ÿÿÿÿÿ5.18ÿÿÿ0.000ÿÿÿÿÿ.0121783ÿÿÿÿ.0270055
                ÿÿÿÿÿÿÿ_consÿ|ÿÿ-.6887166ÿÿÿ.7157624ÿÿÿÿ-0.96ÿÿÿ0.336ÿÿÿÿ-2.091585ÿÿÿÿ.7141519
                ------------------------------------------------------------------------------

                .ÿ
                .ÿ//ÿOneÿmethod,ÿquickÿandÿdirty,ÿperhaps
                .ÿpredictÿdoubleÿe_mpg,ÿresidualsÿeq(#1)

                .ÿpredictÿdoubleÿe_hea,ÿresidualsÿeq(#2)

                .ÿpwcorrÿe_*,ÿsig

                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿe_mpgÿÿÿÿe_hea
                -------------+------------------
                ÿÿÿÿÿÿÿe_mpgÿ|ÿÿÿ1.0000ÿ
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|
                ÿÿÿÿÿÿÿe_heaÿ|ÿÿ-0.0138ÿÿÿ1.0000ÿ
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿ0.9071
                ÿÿÿÿÿÿÿÿÿÿÿÿÿ|

                .ÿ
                .ÿ//ÿAlternative,ÿmaybeÿmoreÿprincipled
                .ÿsemÿ(e_mpgÿ)ÿ(e_heaÿ),ÿ///
                >ÿÿÿÿÿÿÿÿÿnocnsreportÿnodescribeÿnofootnoteÿnolog

                StructuralÿequationÿmodelÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿNumberÿofÿobsÿ=ÿ74
                Estimationÿmethod:ÿml

                Logÿlikelihoodÿ=ÿ-276.03339

                ---------------------------------------------------------------------------------
                ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿOIM
                ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ|ÿCoefficientÿÿstd.ÿerr.ÿÿÿÿÿÿzÿÿÿÿP>|z|ÿÿÿÿÿ[95%ÿconf.ÿinterval]
                ----------------+----------------------------------------------------------------
                ÿÿÿÿÿmean(e_mpg)|ÿÿÿ5.72e-14ÿÿÿ.3943236ÿÿÿÿÿ0.00ÿÿÿ1.000ÿÿÿÿÿÿ-.77286ÿÿÿÿÿÿ.77286
                ÿÿÿÿÿmean(e_hea)|ÿÿ-2.80e-14ÿÿÿ.0836526ÿÿÿÿ-0.00ÿÿÿ1.000ÿÿÿÿ-.1639561ÿÿÿÿ.1639561
                ----------------+----------------------------------------------------------------
                ÿÿÿÿÿÿvar(e_mpg)|ÿÿÿ11.50634ÿÿÿ1.891631ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ8.336823ÿÿÿÿ15.88086
                ÿÿÿÿÿÿvar(e_hea)|ÿÿÿ.5178342ÿÿÿ.0851314ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.3751924ÿÿÿÿÿ.714706
                ----------------+----------------------------------------------------------------
                cov(e_mpg,e_hea)|ÿÿ-.0336703ÿÿÿÿ.283785ÿÿÿÿ-0.12ÿÿÿ0.906ÿÿÿÿ-.5898787ÿÿÿÿ.5225381
                ---------------------------------------------------------------------------------

                .ÿestimatesÿstoreÿCovariance

                .ÿ
                .ÿquietlyÿsemÿ(e_mpgÿ)ÿ(e_heaÿ),ÿcovariance(e_mpg*e_hea@0)ÿ

                .ÿlrtestÿCovariance

                Likelihood-ratioÿtest
                Assumption:ÿ.ÿnestedÿwithinÿCovariance

                ÿLRÿchi2(1)ÿ=ÿÿÿ0.01
                Probÿ>ÿchi2ÿ=ÿ0.9055

                .ÿ
                .ÿexit

                endÿofÿdo-file


                .


                If you're that interested in some kind of null hypothesis significance test that the covariance of the residuals is exactly zero, then maybe fit a model using sem or gsem from the beginning.
                Hi Joseph,

                The code works well for me. Thanks alot!

                Comment


                • #9
                  Originally posted by Melody Brown View Post
                  The code works well for me. Thanks alot!
                  Keep in mind that you basically did that test already when you specified the corr option back up in #1. According to the user's manual entry for the command, "corr displays the correlation matrix of the residuals between equations and performs a Breusch–Pagan test for independent equations; that is, the disturbance covariance matrix is diagonal".

                  Comment


                  • #10
                    Originally posted by Joseph Coveney View Post
                    Keep in mind that you basically did that test already when you specified the corr option back up in #1. According to the user's manual entry for the command, "corr displays the correlation matrix of the residuals between equations and performs a Breusch–Pagan test for independent equations; that is, the disturbance covariance matrix is diagonal".
                    Got it! Thanks a lot, Joseph!

                    Comment

                    Working...
                    X