Announcement

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

  • need help on on colnumb or rownumb

    Any idea what's going with matric D1 and F1 in below. I have a matric D1 which contains some post estimation of from a margins command. But when I tried to get the column number of 1._at#1.Treatment in D1, the STATA issues a error message. But if I go one step further to let another mat F1 to be the same as D1 (mat F1=D1), it won't have problem with F1 for the same operation. What is going on?




    . mat list D1

    D1[9,6]
    1._at# 1._at# 1._at# 2._at# 2._at# 2._at#
    1.Treatment 2.Treatment 3.Treatment 1.Treatment 2.Treatment 3.Treatment
    b .97819882 1.1457846 1.0719707 .75463889 .96552951 .88649156
    se .01749367 .03349974 .03991627 .01724896 .03304899 .03991627
    z 55.917298 34.20279 26.855479 43.749819 29.215101 22.208775
    pvalue 0 2.20e-256 7.28e-159 0 1.25e-187 2.83e-109
    ll .94391186 1.0801263 .99373623 .72083155 .90075468 .8082571
    ul 1.0124858 1.2114429 1.1502052 .78844623 1.0303043 .96472602
    df . . . . . .
    crit 1.959964 1.959964 1.959964 1.959964 1.959964 1.959964
    eform 0 0 0 0 0 0

    . global aa=colnumb(D1, "1._at#1.Treatment")
    type mismatch
    r(109);

    .
    . mat F1=D1

    . global aa=colnumb(F1, "1._at#1.Treatment")

    . di "$aa"
    1



  • #2
    Did you ever solve this? I'm having a similar issue where colnumb returns "type mismatch" but if I just assign that matrix to another matrix it works. So weird!

    Comment


    • #3
      What version of Stata do you have? From version 16, the matrix functions -colnumb()- and -rownumb()- are superseded by more straightforward ways to refer to matrix columns and rows. See

      Code:
      help matrix extraction
      for details. In any case, #1 most likely did not get a response due to lack of a reproducible example. You will increase your chances of making progress by providing one (FAQ Advice #12 explains what is required).

      Comment


      • #4
        The problem in post #1 is likely the result of having not only a Stata matrix named D1 but also a variable in the current dataset named D1.
        Code:
        . mat D1 = 1,2,3 \ 4,5,6
        
        . mat list D1
        
        D1[2,3]
            c1  c2  c3
        r1   1   2   3
        r2   4   5   6
        
        . display colnumb(D1,"c1")
        1
        
        . gen D1 = 3
        
        . mat list D1
        
        D1[2,3]
            c1  c2  c3
        r1   1   2   3
        r2   4   5   6
        
        . display colnumb(D1,"c1")
        type mismatch
        r(109);
        
        . display colnumb(matrix(D1),"c1")
        1
        
        .
        I seem to recall in Stata's copious documentation a discussion of namespaces that explains rules about using or not using the same name for two different things. I cannot find it at the moment, however.

        Comment

        Working...
        X