Announcement

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

  • Marginsplots with MI

    I'm trying to get both the margins function and the marginsplot function to work with an MI dataset.

    I have tried using the approach found here:

    http://www.statalist.org/forums/foru...action-effects

    I use the code:

    mi estimate: regress stdsharevalue treatment##Canadian

    generate TC = treatment*Canadian

    pr bogus ,eclass
    tempname b V sample
    mat `b' = e(b)
    mat `V' = e(V)
    mat rown `b' = y
    mat coln `b' = treatment Canadian i.treatment#i.Canadian _cons
    mat rown `V' = treatment Canadian i.treatment#i.Canadian _cons
    mat coln `V' = treatment Canadian i.treatment#i.Canadian _cons
    g `sample' = e(sample)
    eret post `b' `V' , e(`sample')
    end

    mi estimate: regress stdsharevalue treatment Canadian TC
    bogus
    margins ,dydx(Canadian)

    However, I get this error after I use the bogus program:
    conformability error
    r(503);

    Any insights as to why this is happening, or how to get around this would be appreciated.


  • #2
    Megan, you are using factor variable notation in your mi estimate command, so you can use mimrgns (SSC) to get average marginal effects and use marginsplot. Code

    Code:
    mi estimate: regress stdsharevalue treatment##Canadian 
    mimrgns , dydx(Canadian) cmdmargins
    marginsplot , noci
    Note the cmdmargins option specified with mimrgns that is necessaryfor marginsplot to work. Also note the noci option specified with marginsplot that I included because the confidence intervals used by marginsplot will be wrong. You can (and should) read more about both topics in the help for mimrgns.

    I do not recommend using the bogus-approach that I have suggested earlier with multiply imputed data. Here is why. In general, if you think you need to use this approach then you are probably overlooking something.

    Best
    Daniel

    Comment


    • #3
      I think the problem is that you are providing only 1 variable name, i.treatment#i.Canadian, whereas the original e(b) matrix will actually have 4 columns devoted to this interaction.

      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      .
      . //      MAKE A SECOND DICHOTOMOUS VARIABLE IN THIS DATA SET
      . gen byte good = (rep78 == 5)
      
      .
      . regress price i.foreign##i.good
      
            Source |       SS           df       MS      Number of obs   =        74
      -------------+----------------------------------   F(3, 70)        =      0.33
             Model |  8893742.52         3  2964580.84   Prob > F        =    0.8026
          Residual |   626171654        70  8945309.34   R-squared       =    0.0140
      -------------+----------------------------------   Adj R-squared   =   -0.0283
             Total |   635065396        73  8699525.97   Root MSE        =    2990.9
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
           foreign |
          Foreign  |   301.2446   931.1321     0.32   0.747     -1555.84    2158.329
            1.good |   -1942.64   2156.748    -0.90   0.371    -6244.138    2358.858
                   |
      foreign#good |
        Foreign#1  |   1786.922   2516.661     0.71   0.480    -3232.401    6806.245
                   |
             _cons |    6147.14    422.973    14.53   0.000     5303.547    6990.733
      ------------------------------------------------------------------------------
      
      .
      . matrix list e(b)
      
      e(b)[1,9]
                   0b.           1.          0b.           1.  0b.foreign#  0b.foreign#  1o.foreign#   1.foreign#            
              foreign      foreign         good         good      0b.good      1o.good      0b.good       1.good        _cons
      y1            0    301.24462            0     -1942.64            0            0            0    1786.9221      6147.14
      Even though those other three column names are for omitted variables, they have to be there.

      Note: Assumes treatment and Canadian are both dichotomous. If either has more than 2 levels, then even more column names will be needed.

      Added: Crossed with #2. Note that I was just offering Megan an explanation and solution to her conformability error. I don't adequately understand the issues about the appropriateness of this overall approach, and I defer entirely to Daniel Klein's opinion on this.
      Last edited by Clyde Schechter; 12 Apr 2017, 14:17.

      Comment


      • #4
        Thanks so much, Daniel. This is really helpful.

        Comment


        • #5
          There is actually one more problem with Megan's code. mi estimate will not even post anything to e(b) or e(V) if not told to do so. So Megan is lucky the error occurred, because whatever would have been in e(b) and e(V) and plotted would very likely not have been what she was hoping for.

          To repeat myself, I do not recommend using the bogus-approach, unless you really understand what you are doing and why you are doing it. Perhaps I should have not posted it in the first place, although I did include a critical discussion that should be taken literally. I have no idea whether the results of such an approach would create valid results in any way. Probably not.

          Best
          Daniel

          Comment


          • #6
            Ah, thanks, Claude. That makes sense re the conformability error. Will store for future reference.

            Comment

            Working...
            X