Announcement

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

  • Extracting predictor name, coeffs, p-values, 95% CIs after using mixed

    Hi,

    I am running many univariable analyses of the form:

    foreach myvar of varlist x1 x2 ......xn {
    mixed outcome `myvar' || id:,nolog noretable
    }

    I would like to collect in an easy to scroll file like one row per variable the following:

    predictor name, coef, p-value, 95%CI

    Any help would be greatly appreciated.

    Thank you,

    Nikos

  • #2
    As the FAQ states, if you are not using the current version (16.1) of Stata, you should say so. Accordingly, the following code assumes you are running version 16--it will not work in earlier versions.

    Code:
    frame create results str32 predictor float(coeff lb ub p-value)
    
    foreach myvar of varlist x1 x2 xn {
        mixed outcome `myvar' || id:, nolog noretable
        matrix M = r(table)
        post frame results ("`myvar'") (`=M[1, 1]') (`=M[5, 1]') (`=M[6, 1]') (`=M[4, 1]')
    }
    frame change results
    list, noobs clean
    You may want to apply some display formats to the variables in the results frame before you -list- them. You can save the data in frame results into a file if you like.

    Comment


    • #3
      Dear Clyde,

      Thank you for your response.

      I have Stata 16 and just updated to 16.1.

      I tried to run the code but I get an error right in the beginning. Any suggestions:

      . frame create results str32 `myvar' float(coeff lb ub p-value)
      invalid syntax
      r(198);

      I am trying also the help files

      Thank you,

      Nikos

      Comment


      • #4
        The command that is giving you the error appears nowhere in the code I posted in #2. At the time of the -frame create- command, local macro myvar is undefined, and that is why you are getting a syntax error. Re-read the code in #2 and copy the -frame create- command exactly as it appears there.

        Comment


        • #5
          Thank you Clyde

          I have used your code with some real variables exactly as provided and I still get the same error:

          frame create results str32 predictor float(coeff lb ub p-value)

          foreach myvar of varlist Age Height_m Weight_kg BMI BSA AgeMaxHR {
          mixed Distance_ `myvar' ||Patient_ID:,nolog noretable
          matrix M = r(table)
          post frame results ("`myvar'") (`=M[1, 1]') (`=M[5, 1]') (`=M[6, 1]') (`=M[4, 1]')
          }
          frame change results
          list, noobs clean


          ************************************************** ************************
          . do "C:\Users\nikos\AppData\Local\Temp\STD1780_000000. tmp"

          . frame create results str32 predictor float(coeff lb ub p-value)
          invalid syntax
          r(198);

          end of do-file

          r(198);


          Best,
          Nikos

          Comment


          • #6
            Sorry, there's a typo in that line: p-value is not a legal variable name. I meant p_value.

            In checking this out, I also noticed another error. The command that begins -post frame- should begin with -frame post-.

            With those changes, the code runs without error messages.

            Comment


            • #7
              Dear Clyde,

              I have managed to solve my problem with the following code:
              ***

              webuse nlswork, clear


              postfile results str10 myvar coef lb ub p_value using results, replace

              foreach myvar of varlist grade age ttl_exp tenure{

              mixed ln_w `myvar' || id:, nolog noretable

              matrix M = r(table)

              post results ("`myvar'") (`=M[1, 1]') (`=M[5, 1]') (`=M[6, 1]') (`=M[4, 1]')

              }


              postclose results

              ***
              Thank you and best wishes,

              Nikos

              Comment

              Working...
              X