Announcement

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

  • Twoway contour for significant average marginal effects

    Hi,

    I run this four-way interaction model in Stata 14:

    xtreg Y c.X1##c.X2##c.X3##X4 Controls i.country i.year,r

    Then, I type the following:

    margins, dydx(X1) at (X2=(0(0.1)1) X3=(0(0.1)1) X4=(0 1)) saving (predictions,replace)

    How can I get the "twoway contour" to view the results for only significant average marginal effects of X1 on Y conditional on X2 and X3 when X4 equals 0 and 1 respectively?

    Best,

    Lütfi

  • #2
    In your saved prediction dataset you can plot the contour where _pvalue is less than your chosen level of significance. However, if there are distinct significance regions, then there will empty areas in the graph region or it will interpolated between the significant areas to fill in the missing z-values. Another option would be to use contour lines to indicate significance.

    Code:
    sysuse auto,clear
    regress price c.gear##c.weight##c.displacement
    qui margins, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400)) saving(tmp1,replace)
    
    use tmp1,clear
    
    
    twoway  contour _mar _at2 _at3  , clegend(pos(3) width(*.5)  )  zlabel(,labsize(*.75)) /// 
        ztitle("")  ccut(15000(-5000)-20000) /// 
        xlabel( 50(50)400) ylabel(2500(500)4000) ///  
        title(Gear Marginal Effects on Price ) name(gr1,replace)  
        
    twoway contour _margin _at2 _at3  if _pvalue < .05, clegend(pos(3) width(*.5)  )  zlabel(,labsize(*.75)) /// 
        ztitle("")     ccut(5000(-5000)-20000)    /// 
        xlabel( 100(50)400) ylabel(2500(500)4000) /// 
        title(Interpolated Significant Gear Marginal Effects on Price) /// 
        name(gr2,replace)
    
    twoway contour _margin _at2 _at3  if _pvalue < .05, clegend(pos(3) width(*.5)  )  zlabel(,labsize(*.75)) /// 
        ztitle("")     ccut(5000(-5000)-20000)  interp(none)   /// 
        xlabel( 100(50)400) ylabel(2500(500)4000) /// 
        title(Significant Gear Marginal Effects on Price) /// 
        name(gr3,replace)
        
    twoway  contour _mar _at2 _at3  , clegend(pos(3) width(*.5)  )  zlabel(,labsize(*.75)) /// 
        ztitle("") ccut(15000(-5000)-20000)    /// 
        || contourline  _pvalue _at2 _at3  , plegend(off) colorlines  /// 
        scolor(black) ecolor(black) crule(linear)  /// 
        clw(vthin vthin   medium medthick  )  ccut(.1 .05 .01  0)     /// 
        || , xlabel( 50(50)400) ylabel(2000(500)4000) /// 
        title(Gear Marginal Effects on Price ) /// 
        note(Contour Lines Indicate Significant Marginal Effect (10%, 5%, 1%)  ) /// 
        name(gr4,replace)
    
    graph combine gr1 gr2 gr3 gr4, row(4)  ysize(12)
    Click image for larger version

Name:	contour.png
Views:	1
Size:	77.1 KB
ID:	1693705

    Comment


    • #3
      Thank you for your reply.

      A couple of questions:

      1-) Can I make the predictions for observed values of the covariates, which means, rather than;

      qui margins, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400)) saving(tmp1,replace) something like; qui margins, dydx(gear) at(weight=(OBSERVED VALUES ONLY) displacement= (OBSERVED VALUES ONLY)) saving(tmp1,replace) Is it possible and preferable?

      Whether yes or not, can I scatter the observations of weight and displacement on the same graph? So far the only solution I can figure out is to copy-paste the observations of weight and displacement into the predictions file (tmp1) and then add the following to the end of twoway command:

      scatter weight displacement

      However, if the aforementioned "OBSERVED VALUES ONLY" prediction is somehow possible, then, observations of weight and displacement will be already in the predictions file.

      2-) I have a fourth covariate in my regression (X4), a dichotomous one, so I guess I have to make two separate graphs, when X4=0 and X4=1, correct?

      Then, which one is more accurate?


      (i) margins X4, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400) X4=0) saving(tmp1,replace)
      margins X4, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400) X4=1) saving(tmp2,replace)

      or

      (ii) margins if X4==0, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400)) saving(tmp1,replace)
      margins if X4==1, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400)) saving(tmp2,replace)

      or

      (iİi) margins if X4==0, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400) X4=0) saving(tmp1,replace)
      margins if X4==1, dydx(gear) at(weight=(2000(50)4000) displacement= (50(50)400) X4=1) saving(tmp2,replace)

      3-) How can I substitute


      ccut(5000(-5000)-20000) with something else so that I can cluster the marginal effects into unequal ranges of my own preferance? Mnay thanks in advance, Lütfi

      Comment

      Working...
      X