Announcement

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

  • User-program MRTAB issue when using "mtest" option

    Hi there -- long time visitor, first time poster.

    Using Stata SE 13.1 with the following user-installed programs relevant to my problem:

    MRTAB from http://fmwww.bc.edu/RePEc/bocode/m (module to compute one- and two-way tables of multiple responses)
    Version 8.2

    I can't for the life of me figure out why this isn't working, given that it seemingly worked up until today with no tweaking to the specific line of code:

    Code:
              
    // Macro
       local ccctabs "any_ccc cardio_flag gastro_flag malig_flag metabolic_flag neuromuscular_flag congen_gendefect_flag renal_flag respiratory_flag"
    
    // Code
       mrtab `ccctabs', by(reach_pat) col mtest nonames title(Complex Chronic Conditions) include
    When I enable Set Trace On, the issue seems to be around the "mtest" option, which I've used previously with the same set of variables to no issue. Simply removing it allows the command to proceed.

    Code:
    .... (trace on output with no issue)
      
     - ret add
        - }
        - if _rc {
        drop _all
        exit _rc
        }
        --------------------------------------------------------------------------------------------------- end tabi    ---
        - mat `M'=nullmat(`M') \ (`r(chi2`mlrchi2')',`r(p`mlrchi2')')
        = mat __00000J=nullmat(__00000J) \ (,)
    
    
    ,    not found        // <---------------------------PROBLEM HERE
    
    
    
        }
        ---------------------------------------------------------------------------------------- end mrtab.Mulipletest    ---
        local df=`nby'-1
        }
        ------------------------------------------------------------------------------------------------------ end mrtab    --
    All my variables are described the exact same as below:

    Code:
    storage             display    value
    variable name    type    format    label      variable label
                        
    renal_flag           long    %8.0g    la_yesno    renal_flag
    Any help would be much appreciated!

  • #2
    Also, here's a sample from my dataset

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(uniqueid any_ccc) long(cardio_flag gastro_flag malig_flag metabolic_flag neuromuscular_flag congen_gendefect_flag renal_flag respiratory_flag) byte reach_pat
     10945195008 1 0 1 0 0 1 1 0 0 0
     10945195008 1 0 1 0 0 1 1 0 0 0
     12422325248 1 0 1 0 0 1 0 0 0 1
     12594084864 1 0 1 0 0 0 1 0 1 0
     12693374976 1 0 1 0 0 1 1 0 0 0
     20704395264 1 0 1 0 1 1 0 0 0 0
     21452914688 1 0 0 0 0 1 0 0 0 0
     21452914688 1 0 0 0 0 1 0 0 0 0
     22961264640 1 1 1 0 0 1 0 0 0 0
     22961264640 1 1 1 0 0 1 0 0 0 0
     40104194048 1 0 1 0 0 1 0 0 0 0
     40104194048 1 0 1 0 0 1 0 0 0 0
     40104194048 1 0 1 0 0 1 0 0 0 0
     40104194048 1 0 1 0 0 1 0 0 0 0
     40104194048 1 0 1 0 0 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     42766893056 1 0 1 0 1 1 0 0 0 0
     43034763264 1 0 0 0 1 1 1 0 0 0
     43034763264 1 0 0 0 1 1 1 0 0 0
     43840643072 1 0 1 0 0 1 1 0 0 0
     43840643072 1 0 1 0 0 1 1 0 0 1
     44555923456 1 0 0 0 0 1 0 0 0 0
     44555923456 1 0 0 0 0 1 0 0 0 0
     44555923456 1 0 0 0 0 1 0 0 0 0
     44684136448 1 0 0 0 0 1 0 0 0 1
     45533175808 1 0 1 0 0 1 1 0 1 0
     46439866368 1 0 1 0 1 1 0 0 0 0
     46439866368 1 0 1 0 1 1 0 0 0 0
     46656053248 1 0 1 0 1 1 0 0 0 0
     46656053248 1 0 1 0 1 1 0 0 0 0
     46656053248 1 0 1 0 1 1 0 0 0 0
     46656053248 1 0 1 0 1 1 0 0 0 0
     46794452992 1 0 1 0 1 1 0 0 0 0
     46794452992 1 0 1 0 1 1 0 0 0 0
     46794452992 1 0 1 0 1 1 0 0 0 0
    end
    label values cardio_flag la_yesno
    label values gastro_flag la_yesno
    label values malig_flag la_yesno
    label values metabolic_flag la_yesno
    label values neuromuscular_flag la_yesno
    label values congen_gendefect_flag la_yesno
    label values renal_flag la_yesno
    label values respiratory_flag la_yesno
    label values any_ccc la_yesno
    label def la_yesno 0 "No", modify
    label def la_yesno 1 "Yes", modify
    label values reach_pat la_reach_pat
    label def la_reach_pat 0 "No - Reached Patient", modify
    label def la_reach_pat 1 "Yes - Reached Patient", modify

    Comment


    • #3
      Welcome to Statalist, Kevin. It's always good to hear from someone who has been following Statalist for long enough to know how to effectively present a problem.

      I can't claim any knowledge of mrtab but that won't stop me from making educated guesses.

      First, you say that it's worked up until today with no tweaking to the specific line of code. You don't say when the most recent prior usage was. You haven't upgraded to Stata 15 in the interim, have you?

      This suggests to me there's a problem with the particular data you are pushing through it today.

      You've already shown yourself willing to experiment by adjusting the options. I suggest experimenting systematically with rerunning the command with fewer variables. Start with one and add them one at a time until it fails. Then take the first one out, see if it still fails. Maybe you can get down to a pair of variables sufficient to make it fail. Then there's something about the pattern of data in those two variables that is causing the problem.

      Another option is to contact the author of the current version at the email address given at the end of the help file.

      Let us know if this is helpful. Below I've posted some notes of my discoveries, TL;DR for anyone who's not a real fanatic.

      The trace is immensely useful, for once. Look here:
      Code:
         - mat `M'=nullmat(`M') \ (`r(chi2`mlrchi2')',`r(p`mlrchi2')')
         = mat __00000J=nullmat(__00000J) \ (,)
      What we see is that both the return values r(chi2`mlrchi2') and r(p`mlrchi2') from some earlier process are null. Using viewsource mrtab.ado we find the following code:
      Code:
      program define Mulipletest
          args H novcby noi nby M mtest mchi2 mlrchi2
          forv i=1/`noi' {
              local freqir1 ""
              local freqir2 ""
              forv j=1/`nby' {
                  local freqir1 "`freqir1'`=`H'[`i',`j']' "
                  local freqir2 "`freqir2'`=`novcby'[1,`j']-`H'[`i',`j']' "
              }
              qui tabi `freqir1' \ `freqir2', `mchi2' nofreq
              mat `M'=nullmat(`M') \ (r(chi2`mlrchi2'),r(p`mlrchi2'))
          }
          mat coln `M'=chi2 p
          _mtest adjust `M', mtest(`mtest') pindex(2) replace
          mat `M'=r(result)
      end
      Now it turns out that the local mlrchi2 will be null because you did not specify the mlrchi2 option, and the code is looking for the r(chi2) and r(p) values that were supposed to be set by the tabi command but apparently were not. My suspicion is that something derailed tabi, and for whatever reason, tabi did not throw an error. You could scroll up in your trace and look for something that might be a "warning" message, or perhaps something like missing values being stowed into the freqir1 and freqir2 locals, and see if that gives you any ideas. You could copy the ado file, edit the tabi command, and remove the "quietly" in front of it, and see what transpires. Seems like a neverending search, though.

      Comment


      • #4
        Thanks so much for the reply. Haven't upgraded Stata -- just meant to say that I didn't tweak the surrounding code/specific variables in the code recently, but had run the code as part of a larger do-file daisy chain with no problem previously. I wonder if, even though the code/variables aren't connected, something about my tweaking another line of code elsewhere in my daisy chain has messed things up?

        It's just so odd that the mtest function wouldn't work here, but in another database with different observations (but same variables), it works fine. I think you're right that it has something to do with my data rather than the mrtab program itself. Going to keep at it and see if I can find anything worth posting here for additional support.

        Also, for what it's worth, this is a small piece of a larger do-file, which I narrowed down as the problem section. Would it be helpful to post the do-file in it's entirety?

        Comment


        • #5
          Alright, I ran the "set trace on" function for only that problematic piece of code, then searched my results window for the "freqir1" variable, and here's what I found from the trace:

          Code:
          -------------------------------------------------------------------------------------- begin mrtab.Mulipletest ---
          - args H novcby noi nby M mtest mchi2 mlrchi2
          - forv i=1/`noi' {
          = forv i=1/9 {
          - local freqir1 ""
          - local freqir2 ""
          - forv j=1/`nby' {
          = forv j=1/2 {
          - local freqir1 "`freqir1'`=`H'[`i',`j']' "
          = local freqir1 "39 "
          - local freqir2 "`freqir2'`=`novcby'[1,`j']-`H'[`i',`j']' "
          = local freqir2 "0 "
          - }
          - local freqir1 "`freqir1'`=`H'[`i',`j']' "
          = local freqir1 "39 63 "
          - local freqir2 "`freqir2'`=`novcby'[1,`j']-`H'[`i',`j']' "
          = local freqir2 "0 0 "
          - }
          - qui tabi `freqir1' \ `freqir2', `mchi2' nofreq
          = qui tabi 39 63  \ 0 0 , ch nofreq
          ------------------------------------------------------------------------------------------------- begin tabi ---

          Comment


          • #6
            Found the problem variable: malig_flag. Now to investigate...

            Comment


            • #7
              Aaaaand I think I've got it. It is the only variable in the varlist that has ZERO observations in the dataset! And given that mtest cross-compares chi2 individually, if there is no observation, the test fails.

              William, thank you for pointing me in the right direction!

              Comment


              • #8
                Follow-up question: is there a way to add a condition to whether an item in a local macro is included in the command including the local macro? In my case, I don't want to delete "malig_flag" from my local macro because I know that there are observations in other datasets where this code will be run, but in this particular dataset, there are no observations.

                Comment


                • #9
                  First, hey cool, you found the problem. I'm just a little gratified that the direction I aimed you in was the right one, but more so that it was enough to get you to a solution.

                  Now, on to your question in post #8. If I understand you correctly, you have
                  Code:
                  local ccctabs "any_ccc cardio_flag gastro_flag malig_flag metabolic_flag neuromuscular_flag congen_gendefect_flag renal_flag respiratory_flag"
                  and that list is used for a lot of things in your processing, but you want to be able to set up a second local that you can populate with stuff to be excluded from the mrtab command. If I got that right, here's an approach; the relevant documentation is in help macro list.
                  Code:
                  . local ccctabs "any_ccc cardio_flag gastro_flag malig_flag metabolic_flag neuromuscular_flag congen_gendefect_flag renal_flag respiratory_flag"
                  
                  . local mrtab_not "malig_flag renal_flag"
                  
                  . local mrtab_ccc : list ccctabs - mrtab_not
                  
                  . display "`mrtab_ccc'"
                  any_ccc cardio_flag gastro_flag metabolic_flag neuromuscular_flag congen_gendefect_flag respiratory_flag

                  Comment


                  • #10
                    In some cases, the chi2 test for an individual row of the table cannot be computed (if the prevalence is 0 or 100 in all groups). The version of -mrtab- available from the Stata Journal throws an error in this case because it tries to grab the nonexistent chi2 test stats from tabi in a way that leads to invalid syntax:
                    Code:
                       - mat `M'=nullmat(`M') \ (`r(chi2`mlrchi2')',`r(p`mlrchi2')')
                       = mat __00000J=nullmat(__00000J) \ (,)
                    In the version of mrtab available from SSC this is fixed:
                    Code:
                       - mat `M'=nullmat(`M') \ (r(chi2`mlrchi2'),r(p`mlrchi2'))
                       = mat __00000J=nullmat(__00000J) \ (.,.)
                    That is, the SSC version of mrtab will record missing values for the chi2 stats and proceed.
                    The solution hence is to install the SSC version of mrtab:
                    Code:
                    . ssc install mrtab, replace
                    Maybe also type -discard- or -clear all- or restart Stata to make sure that Stata does not use the old version of -mrtab- that might still be in the working memory.
                    If the problem persists then maybe there's an old version of mrtab lying around along the adopath. Type
                    Code:
                    . findfile mrtab.ado, all
                    to see a list of all instances of mrtab.ado found by Stata.
                    ben

                    Comment


                    • #11
                      Ben -- thanks so much for the update. I'll be sure to reinstall from SSC!

                      Also, as an update to my last query that William responded to -- I ended up going with Nick Cox's findname program and used the following code to circumnavigate the issue:

                      Code:
                      findname *_flag, any(@ == 1) local(ccctabs)

                      Comment

                      Working...
                      X