Announcement

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

  • missing values after matrix multiplication

    Can someone tell me why the vector s1 below contains missing values?


    Code:
    version 14.2
    
    webuse sysdsn1, clear
    keep if insure !=.
    mlogit insure age male nonwhite i.site
    matrix define b = e(b)
    tempname noomit
    _ms_omit_info b
    local cols = colsof(b)
    matrix `noomit' =  J(1,`cols',1) - r(omit)
    tab insure, g(insure)
    tab site, g(site)
    
    mata
    
    st_view(y1=.,., "insure1")
    st_view(y2=.,., "insure2")
    st_view(y3=.,., "insure3")
    
    N=rows(y1)
    cons=J(N,1,1)
    st_view(X=.,.,"age male nonwhite site2 site3")
    X=X, cons
    b=select(st_matrix("b"),(st_matrix(st_local("noomit"))))
    
    
    xb2 = X*b[1..6]'
    xb3 = X*b[7..12]'
    p1 = 1 :/ (1 :+ exp(xb2) :+ exp(xb3))
    p2 = exp(xb2) :/ (1 :+ exp(xb2) :+ exp(xb3))
    p3 = exp(xb3) :/ (1 :+ exp(xb2) :+ exp(xb3))
    
    s1 = X'*(y2 - p2)
    
    end
    Thanks in advance!

    Jessica

  • #2
    You have a missing value in your input data.
    Code:
    . misstable summarize
                                                                   Obs<.
                                                    +------------------------------
                   |                                | Unique
          Variable |     Obs=.     Obs>.     Obs<.  | values        Min         Max
      -------------+--------------------------------+------------------------------
          noinsur0 |       288                 328  |      2          0           1
          noinsur1 |       286                 330  |      2          0           1
          noinsur2 |       280                 336  |      2          0           1
               age |         1                 615  |   >500   18.11087    86.07254
      -----------------------------------------------------------------------------
    
    . list age if age==.
    
         +-----+
         | age |
         |-----|
    170. |   . |
         +-----+
    
    . mata X[170,.]
           1   2   3   4   5   6
        +-------------------------+
      1 |  .   0   0   1   0   1  |
        +-------------------------+

    Comment


    • #3
      That was indeed the reason. Thank you!

      Comment

      Working...
      X