Announcement

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

  • Is there way to correct the wrong degree of freedom by using mimrgns command

    Hi, I am trying to produce marginal effects and predicted probabilities, and marginsplot for multiply imputed data by using the command -mimrgns-; however, from the Stata help file, the degree of freedom by using this command is wrong. I found a website from UCLA showing another way to produce marginal effects and plots for multiply imputed data. See below. Does this method get the correct degree of freedom? Thanks!

    https://stats.idre.ucla.edu/stata/fa...-imputed-data/

    The website code:
    Code:
    set seed 1234543
    mi set mlong
    mi register imputed female math read science socst
    mi impute mvn female math read science socst = /// ses write awards, add(10)
    * this is to get the ologit coefficients and standard errors
    mi estimate: ologit ses female read math
    * loop once for each of the response values of ses
    forvalues i=1/3 {
    mi estimate, cmdok: emargins `i' // emargins is defined above
    mat b= e(b_mi) // save mi point estimates
    mat V = e(V_mi) // save mi vce
    * run ologit and margins on the _mi_m==0 data
    quietly ologit ses female read math if _mi_m == 0
    quietly margins, at(female=(0 1) read=(30(10)70)) ///
    atmeans asbalanced predict(outcome(`i')) myret // myret is defined above
    *Technically we ran the program myret between margins and marginsplot.
    *E(cmd) is the eclass scalar that tells Stata what the previous command was.
    * So we have to set that to "margins" for marginsplot to work correctly.
    mata: st_global("e(cmd)", "margins") // set previous cmd to margins
    marginsplot, x(read) recast(line) noci name(ologit`i', replace)

  • #2
    mimrgns is (most likely) for SSC. The command implements the approach outlined at the cited UCLA website; mimrgns does this in a more general way, not hard-coding a specific model. Anyway, since the underlying approach is the same, the degrees of freedom used by marginsplot are (technically) wrong in both cases. Note that mimgrnsdoes produce the correct degrees of freedom. It is marginsplot that cannot access them.

    There is no direct way to pass the correct degrees of freedom to marginsplot. You can either try and modify marginsplot so it accepts an option to pass the degrees of freedom or you can tinker with Ben Jann's coefplot (SSC), which already has such an option. The simple solution is to suppress the confidence intervals in the plot (just like the UCLA website does).

    Even with the (technically) wrong degrees of freedom, the graphs from marginsplot should be fine for reasonable sample sizes.

    Best
    Daniel
    Last edited by daniel klein; 14 Nov 2018, 23:53.

    Comment


    • #3
      Originally posted by daniel klein View Post
      mimrgns is (most likely) for SSC. The command implements the approach outlined at the cited UCLA website; mimrgns does this in a more general way, not hard-coding a specific model. Anyway, since the underlying approach is the same, the degrees of freedom used by marginsplot are (technically) wrong in both cases. Note that mimgrnsdoes produce the correct degrees of freedom. It is marginsplot that cannot access them.

      There is no direct way to pass the correct degrees of freedom to marginsplot. You can either try and modify marginsplot so it accepts an option to pass the degrees of freedom or you can tinker with Ben Jann's coefplot (SSC), which already has such an option. The simple solution is to suppress the confidence intervals in the plot (just like the UCLA website does).

      Even with the (technically) wrong degrees of freedom, the graphs from marginsplot should be fine for reasonable sample sizes.

      Best
      Daniel
      I will agree with Daniel, large samples (N > 1000) shouldn't be substantively that different when done in marginsplot vs coefplot (but it's your responsibility to check if you're using marginsplot).

      Yapeng, if you want to use -coefplot-, you will need to use the -post- option, i.e.

      Code:
      margins ... , post
      estimates store margins
      coefplot margins
      If not, -coefplot- won't be able to "see" the margins results (because they aren't posted into e(b) and e(V); -coefplot- needs those matrices to plot the results.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Originally posted by Weiwen Ng View Post

        I will agree with Daniel, large samples (N > 1000) shouldn't be substantively that different when done in marginsplot vs coefplot (but it's your responsibility to check if you're using marginsplot).

        Yapeng, if you want to use -coefplot-, you will need to use the -post- option, i.e.

        Code:
        margins ... , post
        estimates store margins
        coefplot margins
        If not, -coefplot- won't be able to "see" the margins results (because they aren't posted into e(b) and e(V); -coefplot- needs those matrices to plot the results.
        Thank you, Weiwen. In my personal email contacts with Daniel, I told him I will use -coefplot-. I was just searching for how to use this command. You reply is timely and very helpful!

        Comment

        Working...
        X