Announcement

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

  • Saving entries in variance-covariance matrix

    Dear All,

    I would like to generate the variance-covariance matrix after my estimation and then I want to save some specific entries to be used later.

    Suppose I have:

    Code:
    webuse auto, clear
    reg price rep78 mpg
    mat covar=e(V)
    mat s11=covar[_b[rep78],_b[rep78]]
    local s11=s11[1,1]
    matlist s11
    When I type matlist s11, I was expected to see the variance of the parameter associated to rep78. Instead, I get a missing value. I cannot understand what is wrong. Any suggestion? Tanks in advance.

    Dario

  • #2
    You can refer to the submatrix by position [1,1] or by name using the variable name enclosed in double quotes ["rep78", "rep78"] (see help matrix extraction):

    Code:
    webuse auto, clear
    reg price rep78 mpg
    mat covar=e(V)
    matlist covar
    mat s11=covar["rep78","rep78"]
    mat s11_2=covar[1,1]
    local s11=s11[1,1]
    local s11_2=s11_2[1,1]
    matlist s11
    di "`s11'"
    di "`s11_2'"
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Thanks for your suggestion Carol. I have just realized that

      Code:
      mat s11=covar[_b[rep78], _b[rep78]]


      should be written as
      Code:
      mat s11=covar["rep78, "rep78"]
      Thanks again.

      Dario

      Comment


      • #4
        It is sometimes difficult to know how Stata wants you to refer to a particular entry in a covariance matrix following an estimation command. Particularly in older, versions there were some inconsistencies from one estimation command to the next. Now things are better harmonized, but it can still be difficult to know. So if you are not getting things to work the way you expect them to, or if you just don't even have a good starting guess, run:

        Code:
        matrix list e(V)
        The row stubs and column headers will show you exactly what names to use when referencing the matrix, with the understanding that they go in quotes.

        Comment


        • #5
          Thanks Clyde.

          Comment

          Working...
          X