Announcement

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

  • Why is matrix not found

    I am attempting to run agreement analyses on pairs of variables and then stacking the results in a results matrix. I have created several user-defined programs to run primary analysis, then use the bootstrap to compute confidence intervals on these clusters data, then output to the matrix I called results. The problem is that when the user-defined program is run the second time the results matrix seems to be deleted from memory even though the user defined program doesn't do anything with that matrix. The user-defined programs are as follows:

    This program computes and outputs Gwet's A1C agreement statistic which it returns:
    Code:
    program define pabak, eclass
        args v1 v2
        confirm variable `v1'
        confirm variable `v2'
        tempname z
        quietly kappaetc `v1' `v2', list
        matrix `z' = r(b)
        ereturn scalar v = `z'[1,5]
    end
    This program computes sensitivity and specificity and then uses the clustered boostrap to compute the confidence intervals. It returns the sensitivity, specificity, A1C statistic, and the associated CI:
    Code:
    program define all_stats, rclass
        args part res
        confirm variable `part'
        confirm variable `res'
        tempname sens spec outboot out_1
        quietly diagt `res' `part'
        matrix `sens' = r(sens)    
        matrix `spec' = r(spec)
        quietly bootstrap pbak = e(v), reps(1000) cluster(id): pabak `part' `res'
        matrix `outboot' = e(b), e(ci_bc)'
        matrix `out_1' = `sens', `spec',`outboot'
        return matrix v = `out_1'
    end
    The following code runs the analysis on the first set of variables, creates the matrix results from what is returned from the function all_stats, then re-runs the analysis on the second pair of variables, stores the results in the matrix temp, then attempts to concatenate temp with results.

    Code:
    *Corn    
    all_stats FV01_ HFAV_FV01_
    matrix results = r(v)
    matrix rownames results = Corn
    
    *Peas
    all_stats FV02_ HFAV_FV02_
    matrix temp = r(v)
    matrix rownames temp = Peas
    matrix results = results \ temp
    However, when the last line of code runs, I get the following error message:
    Code:
    results not found
    r(111);
    I have confirmed that the results matrix exists after the first run of all_stats.

    Any help would be greatly appreciated. I am running Stata/SE 14.2 on Windows 10 computer.

    Best,

    Colin

  • #2
    I cannot replicate the problem:

    Code:
    //Note uses Daniel Klein's kappaetc and Paul T Seed's diagt
    version 14.2
    discard
    capture program drop pabak
    program define pabak, eclass
        args v1 v2
        capture variable `v1'
        capture variable `v2'
        tempname z
        quietly kappaetc `v1' `v2', list
        matrix `z' = r(b)
        ereturn scalar v = `z'[1,5]
    end
    
    capture program drop all_stats
    program define all_stats, rclass
        args part res
        capture variable `part'
        capture variable `res'
        tempname sens spec outboot out_1
        quietly diagt `res' `part'
        matrix `sens' = r(sens)    
        matrix `spec' = r(spec)
        quietly bootstrap pbak = e(v), reps(10) cluster(id): pabak `part' `res'
        matrix `outboot' = e(b), e(ci_bc)'
        matrix `out_1' = `sens', `spec',`outboot'
        return matrix v = `out_1'
    end
    
    sysuse auto,clear
    gen id = runiform()<=.5
    
    all_stats  trunk mpg
    matrix results = r(v)
    matrix rownames results = Corn
    
    all_stats price foreign
    matrix temp = r(v)
    matrix rownames temp = Peas
    matrix results = results \ temp
    mat list results
    Code:
    . mat list results
    
    results[2,5]
                  c1          c1        pbak          ll          ul
    Corn           0   98.630137  -.02104105  -.03922763  -.02104105
    Peas           0   98.076923  -.01147795  -.02332529  -.01147795
    Code:
    . which diagt
    c:\ado\plus\d\diagt.ado
    *! diagt 2.032, 30 June 2003
    *! by PT Seed ([email protected])
    *! based on diagtest.ado (Aurelio Tobias, STB-56: sbe36)
    *! and further suggestions from Tom Steichen
    
    . which kappaetc
    c:\ado\plus\k\kappaetc.ado
    *! version 2.0.0 28jun2018 daniel klein

    Comment


    • #3
      The following trivial example shows that your code should work.
      Code:
      . program define all_stats, rclass
        1.     matrix a = (1 , 2 , 3)
        2.     return matrix v = a
        3. end
      
      . 
      . *Corn    
      . all_stats
      
      . matrix results = r(v)
      
      . matrix rownames results = Corn
      
      . 
      . *Peas
      . all_stats
      
      . matrix temp = r(v)
      
      . matrix rownames temp = Peas
      
      . matrix results = results \ temp
      
      . 
      . matrix list results
      
      results[2,3]
            c1  c2  c3
      Corn   1   2   3
      Peas   1   2   3
      
      .
      So I'm not convinced that the code you show us is a complete picture of what you are doing.

      It is good that you confirmed that results exists after the first run of all_stats. Next step would be to add the
      Code:
      matrix dir
      command liberally throughout your code and narrow down the point at which the matrix results vanishes.

      Comment


      • #4
        Earlier versions of diagt (from STB) appear to have cleared matrices from the caller's (i.e. global) namespace. A similar problem was reported and solved here.


        This is an excellent example of why it is of vital importance to tell us where community-contributed software (aka user-written software) that you are using comes from.

        Make sure that you have

        Code:
        . which diagt
        [...]
        *! diagt 2.032, 30 June 2003
        *! by PT Seed ([email protected])
        *! based on diagtest.ado (Aurelio Tobias, STB-56: sbe36)
        *! and further suggestions from Tom Steichen
        from SSC installed.
        Last edited by daniel klein; 11 Nov 2020, 14:32.

        Comment


        • #5
          Here's is what I get when I run which diagt
          Code:
          . which diagt
          c:\ado\plus\d\diagt.ado
          *! diagt 2.0.5, 30 June 2003
          *! by PT Seed ([email protected])
          *! based on diagtest.ado (Aurelio Tobias, STB-56: sbe36)
          *! and further suggestions from Tom Steichen
          So as Daniel Klein points out, it seems to be related to the version of diagt that I have loaded. However, I cannot figure out how to get the version 2.032. When I run ssc install diagt, I get:
          Code:
          checking diagt consistency and verifying not already installed...
          
          the following files already exist and are different:
              c:\ado\plus\d\diagt.ado
              c:\ado\plus\d\diagt.hlp
              c:\ado\plus\d\diagti.ado
              c:\ado\plus\d\diagti.hlp
          
          no files installed or copied
          (no action taken)
          r(602);
          Any recommendations how I can get version 2.032?

          Thanks to everyone who responded so quickly and so thoughtfully. It is much appreciated!

          Comment


          • #6
            Code:
            ado uninstall sbe36_2
            ssc install diagt

            Comment


            • #7
              Worked like a charm! Thanks to everyone for their help.

              Comment

              Working...
              X