Announcement

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

  • marginsplot after mimrgns

    Hello everyone,
    I was trying to use marginsplot command after mimrgns, but it shows the following error "previous command was not margins". Does anyone know where I did wrong. Thanks.
    Lei

  • #2
    I don't have access to Stata at the moment, but I believe the help for mimrgns explains what you need to do to use it with marginsplot.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      mimrgns is probably from the SSC archives. The help file does explain how to get marginsplot to work and also discusses why this extra step is necessary. The relevant part is

      First, the plotted confidence intervals will be based on inappropriate degrees of freedom [...] Second, graphs might be based on imputed values that vary across complete datasets [...] mimrgns applies Rubin's rules to any requested summary statistic in the at() option.
      You can read more in the help file. This said, you need to specify the cmdmargins option with mimrgns.

      Code:
      mi estimate , saving(miestfile) esample(misample) : ...
      mimrgns using miestfile , esample(misample) cmdmargins
      marginsplot , noci
      Best
      Daniel

      Comment


      • #4
        Thank you so much. It worked.

        Comment


        • #5
          Originally posted by Richard Williams View Post
          I don't have access to Stata at the moment, but I believe the help for mimrgns explains what you need to do to use it with marginsplot.
          Thank you Daniel, your answer was very helpful.. I need to have CI within the plot. tried Coefplot based on help page bur didn't give me the result I was looking for. I am looking for a bar graph with trt_ind_n variable being on X axes and margins on the Y axes with CI. Please see the command below.

          margins trt_ind_n
          marginsplot, xdimension(trt_ind_n) recast(bar)



          Many thanks!
          Last edited by Gizem Levent; 25 Apr 2019, 18:01.

          Comment


          • #6
            Originally posted by daniel klein View Post
            mimrgns is probably from the SSC archives. The help file does explain how to get marginsplot to work and also discusses why this extra step is necessary. The relevant part is



            You can read more in the help file. This said, you need to specify the cmdmargins option with mimrgns.

            Code:
            mi estimate , saving(miestfile) esample(misample) : ...
            mimrgns using miestfile , esample(misample) cmdmargins
            marginsplot , noci
            Best
            Daniel
            Thank you Daniel for your answer! It was very helpful. since we can not rely on CI estimates using mimrgn, I tried coefplot as help page suggested. This is the command I would like to mimic with coefplot.

            margins trt_ind_n
            marginsplot, xdimension(trt_ind_n) recast(bar)

            But coeff plot doesn't give margins... I stored the model results.. and tried this below. Do you know if coefplot works with margins?

            coefplot imp_mixed, levels(95) recast(bar)

            Many thanks!

            Gizem

            Comment


            • #7
              Gizem

              I have shown in a basic example how to use coefplot after mimrgns; details could be tricky, though.

              However, do not give up on the CIs from marginsplot just yet. As you have noted and as I have stated in the help file, the CIs are not correct; however, as I also state in the help file, you can often not tell from the graph. I have explained in some detail how you can assess the degree to which marginsplot's CIs will be off. I suggest you follow the steps that I have outlined; chances are, you can safely use marginsplot.

              Best
              Daniel

              Comment


              • #8
                Originally posted by daniel klein View Post
                mimrgns is probably from the SSC archives. The help file does explain how to get marginsplot to work and also discusses why this extra step is necessary. The relevant part is



                You can read more in the help file. This said, you need to specify the cmdmargins option with mimrgns.

                Code:
                mi estimate , saving(miestfile) esample(misample) : ...
                mimrgns using miestfile , esample(misample) cmdmargins
                marginsplot , noci
                Best
                Daniel
                Could you please to tell me what is the miestfile and misample? I am using this commend to plot a predictive value after mi estimate. However, when I direct copy and paste, it caused errors. Many Thanks! Roth

                Comment


                • #9
                  It showed "file miestfile.ster could not be opened" daniel klein

                  Comment


                  • #10
                    Please show the exact code that you have used, including your call to mi estimate.

                    Note that you may use mimrgns just like you would use the regular margins command, i.e., without referring to misetfile (which is a file saved by mi estimate) and misample (which is a variable created by mi estimate). This is documented in the help file. The command works faster when used with saved results but saved results are not required.

                    Best
                    Daniel

                    Comment


                    • #11
                      Dear daniel klein,

                      Sorry! I just saw your reply! Thank you very much for your reply! The codes I have used are:
                      Code:
                      keep if medication==1&gender==1&stroke==1
                      mkspline agesplinea=age, nknots(5) cubic
                      mi estimate, mcerror saving(miestfile) esample(misample): mixed sbpa agesplinea*||country:, reml 
                      mimrgns using miestfile, esample(misample) cmdmargins
                      marginsplot, ci
                      The plot I want to plot and the plot I got are attached for your reference. In addition, would you suggest me to generate different agespline sets in each subset of these four lines which were created from the overall dataset, or I should generate a set of agesplne in the overall dataset?
                      All the best,

                      Roth
                      Attached Files

                      Comment


                      • #12
                        Queran Lin

                        as I have suggested elsewhere, it is probably useful to take a step back and start with the non-imputed dataset. If you can figure out what how to do what you want with complete-case analyses, you can go back to MI.

                        I do not use splines a lot, so I cannot give good theoretical advice here. However, I have serious doubts that margins (and therefore mimrgns) understand splines. For margins to work, you would need to tell it that the variables created by mkspline are mchanically related, i.e, that one variable cannot change its value independently from the other variabels.

                        Even if margins would work, you cannot possibly get differences by gender if you

                        Code:
                        keep if [...] gender==1
                        because your model would onyl include one group.

                        Also, using margins without referring to a factor or specifying at() options will produce one value, which is exactly what you get and show in the picture.

                        I suggest you start a new topic and try to figure out a way to get what you want in the non-imputed case, first.

                        Best
                        Daniel

                        Comment

                        Working...
                        X