Announcement

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

  • Using Margins After Mixed for Random Slope models

    Dear statalist,

    I'm trying to generate predicted marginal effects of a treatment variable (treat) after estimating a random effect model with random coefficients for the treatment. The treatment variable is nested within countries, so the models include random intercepts for that. I interact the treatment with a covariate for countries (gdp). So, the model has the following equation:

    mixed outcome treat##gdp || country:gdp

    My question is how to plot the treatment effect at various levels of gdp, but with excluding the random effect. I want to plot only the fixed effect part of the treatment effect, which would reflect the coefficient on the interaction obtained from a regression table. I used the margins command, but it doesn't seem to be doing that. I also tried to add the option: predict(mu fixedonly), but it didn't work.

    I would appreciate your suggestions.

  • #2
    To start, you’ll need to use factor notation for treat so as to get the margins. Maybe - margins treat, at(gdp=5(2)12) - will do the trick. Obviously, it is up to you so select the range of gdp.
    Best regards,

    Marcos

    Comment


    • #3
      Thanks for the response.

      However, I'm afraid this does not solve my problem. I know the margins command formula. In fact, I run the following:

      margins, dydx(treat) at(gdp=10(10)100)

      The problem is that the output underestimates the interaction effect, which is pretty big when I look at the regression table. My guess is that this have to do with how margin treats random effects. I'm not fully sure if it incorporates or ignores it. I'm also unsure how to be able to generate plots that shows interaction effects similar to those by the regression table.

      Comment


      • #4
        Originally posted by John Ez View Post
        Thanks for the response.

        However, I'm afraid this does not solve my problem. I know the margins command formula. In fact, I run the following:

        margins, dydx(treat) at(gdp=10(10)100)

        The problem is that the output underestimates the interaction effect, which is pretty big when I look at the regression table. My guess is that this have to do with how margin treats random effects. I'm not fully sure if it incorporates or ignores it. I'm also unsure how to be able to generate plots that shows interaction effects similar to those by the regression table.
        Margins should fix all random effects at 0. I think there's a footnote in the output somewhere that you're getting margins for fixed effects only.
        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


        • #5
          A couple of points
          1.
          My guess is that this have to do with how margin treats random effects. I'm not fully sure if it incorporates or ignores it
          No, in the header from margins will have:
          Code:
          Expression   : Linear prediction, fixed portion, predict()
          2. I don't think you want the marginal effect with respect to a discrete change the treat variable, but the adjusted prediction. See for example:

          Code:
          . webuse nlswork,clear
          (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
          
          . rename south treat
          
          . qui mixed ln_wage  i.treat##c.tenure|| id: tenure , nolog noretable 
          
          . //The in the margins compare to the baselevel, treat =0
          . margins, dydx(treat) at(tenure= (10(5)20))  noatlegend 
          
          Conditional marginal effects                    Number of obs     =     28,093
          
          Expression   : Linear prediction, fixed portion, predict()
          dy/dx w.r.t. : 1.treat
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
          0.treat      |  (base outcome)
          -------------+----------------------------------------------------------------
          1.treat      |
                   _at |
                    1  |  -.1753608   .0173657   -10.10   0.000     -.209397   -.1413246
                    2  |  -.2103854   .0261083    -8.06   0.000    -.2615568   -.1592141
                    3  |  -.2454101   .0352159    -6.97   0.000     -.314432   -.1763882
          ------------------------------------------------------------------------------
          Note: dy/dx for factor levels is the discrete change from the base level.
          
          . //the predicted ln_wage @ tenure = 10, 15, 20 & treat = 0, 1
          . margins treat, at(tenure= (10(5)20))  noatlegend 
          
          Adjusted predictions                            Number of obs     =     28,093
          
          Expression   : Linear prediction, fixed portion, predict()
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
             _at#treat |
                  1 0  |   2.050166   .0119183   172.02   0.000     2.026806    2.073525
                  1 1  |   1.874805   .0141068   132.90   0.000     1.847156    1.902454
                  2 0  |    2.28242   .0175168   130.30   0.000     2.248087    2.316752
                  2 1  |   2.072034   .0208181    99.53   0.000     2.031231    2.112837
                  3 0  |   2.514673   .0234209   107.37   0.000     2.468769    2.560577
                  3 1  |   2.269263   .0278764    81.40   0.000     2.214626      2.3239
          ------------------------------------------------------------------------------
          
          . 
          . //Calculating the marginal change by hand @ tenure = 10
          . local margins_at_treat1 "1.treat + 10*tenure + 10*1.treat#c.tenure+ _cons"
          
          . local margins_at_treat0 "10*tenure + _cons"
          
          . lincom (`margins_at_treat1') - (`margins_at_treat0')
          
           ( 1)  [ln_wage]1.treat + 10*[ln_wage]1.treat#c.tenure = 0
          
          ------------------------------------------------------------------------------
               ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                   (1) |  -.1753608   .0173657   -10.10   0.000     -.209397   -.1413246
          ------------------------------------------------------------------------------

          Comment

          Working...
          X