Announcement

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

  • Using -atjoint- in -margins- targeting only one at() condition when multiple at() are specified

    I am working on a logit model containing one interaction between a continuous and a dummy variable. The code I am using is the following (-margins- and -marginsplot- still don't work):

    Code:
    qui logit inverting ethical_dom i.domestic_CEO c.ethical_dom#i.domestic_CEO `ctrls'
    margins, at(ethical_dom=(`ethD_min'(1)`ethD_max') domestic_CEO=(0 1)) contrast(atcontrast(_at(domestic_CEO))) 
    marginsplot, recast(line) xlabel(#5) name(margins_plot, replace)
    The ultimate goal is to obtain a margins plot that draws a line representing the difference in probability, for different levels of ethical_dom (this is the x-axis), between having domestic_CEO==0 and domestic_CEO==1. The line should be surrounded by CIs. I managed to obtain something similar to what I want using this code:

    Code:
    qui logit inverting ethical_dom i.domestic_CEO c.ethical_dom#i.domestic_CEO `ctrls'
    margins, at(ethical_dom=(`ethD_min'(1)`ethD_max'))  over(i.domestic_CEO) contrast(overjoint)
    marginsplot, recast(line) xlabel(#5) name(margins_plot, replace)
    Yet, I understand that using the -over- option is not the same as using the -at- option. What I would like to do is use the -at- option for domestic_CEO, i.e. treat all observations as if at one time they had domestic_CEO==0 and at another time they had domestic_CEO==1.

    Can someone help me use the -atjoint- contrast option, or any other one, to do that?

  • #2
    Hi Ricardo,

    I think you may get what you want typing, -margins r.domestic_CEO, at(ethical_dom=(`ethD_min'(1)`ethD_max'))-

    Comment


    • #3
      Hi Enrique, thank you very much for your previous answer. And apologies for not replying back then—I must have missed your response at the time.

      I have a question similar to my last one. I need to obtain and plot the difference in average marginal effects between two levels of the second at(). However, this time the second at() is a continuous variable. So far, I have tried various approaches, including the code below, but I haven’t succeeded.

      Here is a reproducible example. The code works except for the contrast option, which generates an error:

      Code:
      sysuse auto
      logit foreign price mpg headroom displacement gear_ratio
      
      qui sum price
          global price_min=r(min)
          global price_max=r(max)
          
      qui sum mpg
          global mpg_low=r(mean)-r(sd)
          global mpg_high=r(mean)+r(sd)
          
      margins, dydx(displacement) at(price=($price_min(500)$price_max) mpg=($mpg_low $mpg_high)) contrast(atcontrast(r.mpg)) post
      Thank you very much for any insights may be able to provide!
      Last edited by Riccardo Valboni; 18 Sep 2024, 04:51.

      Comment

      Working...
      X