Announcement

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

  • Pseudo R² for meqrlogit using mi estimate

    Hey,

    I found the following code in this forum to get the pseudo R² for imputed data:

    Code:
    local rhs "armg2 armg3 tbsaburn20 tbsaburn21"
    noi mi estimate, or saving(miest, replace): logistic hodc `rhs', vce(cluster site)
    qui mi query
    local M=r(M)
    scalar r2=0
    scalar cstat=0
    qui mi xeq 1/`M': logistic hodc `rhs'; scalar r2=r2+e(r2_p); lroc, nog; scalar cstat=cstat+r(area)
    scalar r2=r2/`M'
    scalar cstat=cstat/`M'
    noi di "Pseudo R=squared over imputed data = " r2
    noi di "C statistic over imputed data = " cstat
    I have adapted the code for my needs:

    Code:
    local rhs "geschl_n alter_n ethnieend2 schform sozhilf_n selcon bsiagg emp hiesel sozdep eltgew herumf rexnied rexmut rexvat rexle rexfr reakmut_pos reakvat_pos reakle_pos reakfr_pos aus_mit"
    noi mi estimate, or saving(miest, replace): meqrlogit taetaus `rhs', or || klcode: ,
    qui mi query
    local M=r(M)
    scalar r2=0
    scalar cstat=0
    qui mi xeq 1/`M': meqrlogit taetaus `rhs', or || klcode: ,; scalar r2=r2+e(r2_p); lroc, nog; scalar cstat=cstat+r(area)
    scalar r2=r2/`M'
    scalar cstat=cstat/`M'
    noi di "Pseudo R=squared over imputed data = " r2
    noi di "C statistic over imputed data = " cstat
    However, after the "qui mi xeq" command I get the error message "Invalid numlist r(121);". Do you have any idea what I could have done wrong?

    Thanks in advance,
    Yvonne

  • #2
    Yvonne:
    welcome to this forum.
    What if you call the local in your code as:
    Code:
    "`M'"
    instead of;
    Code:
    `M'
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you for your suggestion. Unfortunately, I get the same error message, if I understood your suggestion correctly.

      Code:
      local rhs "geschl_n alter_n ethnieend2 schform sozhilf_n selcon bsiagg emp hiesel sozdep eltgew herumf rexnied rexmut rexvat rexle rexfr reakmut_pos reakvat_pos reakle_pos reakfr_pos aus_mit"
      noi mi estimate, or saving(miest, replace): meqrlogit taetaus `rhs', or || klcode: ,
      qui mi query
      local M=r(M)
      scalar r2=0
      scalar cstat=0
      qui mi xeq 1/"`M'": meqrlogit taetaus `rhs', or || klcode: ,; scalar r2=r2+e(r2_p); lroc, nog; scalar cstat=cstat+r(area)
      scalar r2=r2/`M'
      scalar cstat=cstat/`M'
      noi di "Pseudo R=squared over imputed data = " r2
      noi di "C statistic over imputed data = " cstat

      Comment


      • #4
        Yvonne:
        try your original code (ie, the one you originally posted) just omitting the comma after -klcode-.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Unfortunately the same error message

          Code:
          qui mi xeq 1/`M': meqrlogit taetaus `rhs', or || klcode:; scalar r2=r2+e(r2_p); lroc, nog; scalar cstat=cstat+r(area)

          Comment


          • #6
            Yvonne:
            the usual recipe is to go on with code lines step by step tocheck where Stata throws the error message.
            If the issue is in the line strating with -qui mi xeq 1- stop, for instance, at -klcode:- and see what happens.
            This approach, that heavily draws upon the -what to do when one engine flames out- pilots checklist, sometimes is successful in sniffing out the culprit .
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              I think you need to set trace on (with a depth of 1) so we can see exactly where the problem is; see
              Code:
              help trace

              Comment


              • #8
                Thank you for encouraging me to check the code step by step. I think it has something to do with the ", or" option as I got a different error message after I deleted it. Unfortunately it still did not work.

                I have now used a workaround by running a "normal" logistic regression with clustred standard errors instead of a multilevel model, since I have no second level variables.
                This worked:

                Code:
                local rhs "i.geschl_n alter_n ethnieend2 i.schform i.sozhilf_n selcon bsiagg emp hiesel sozdep eltgew herumf rexnied rexmut rexvat rexle rexfr i.reakmut_pos i.reakvat_pos i.reakle_pos i.reakfr_pos aus_mit"
                noi mi estimate, or saving(miest, replace): logit taetaus `rhs', vce(cluster klcode)
                qui mi query
                local M=r(M)
                scalar r2=0
                scalar cstat=0
                qui mi xeq 1/`M': logit taetaus `rhs'; scalar r2=r2+e(r2_p); lroc, nog; scalar cstat=cstat+r(area)
                scalar r2=r2/`M'
                scalar cstat=cstat/`M'
                noi di "Pseudo R=squared over imputed data = " r2
                noi di "C statistic over imputed data = " cstat
                Thank you again!

                Comment

                Working...
                X