Announcement

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

  • margins does not integrate random effects - Stata 14

    Stata 14 allegedly incorporates random effects into the margins command. However, I am currently using it and it does not seem to do this. For example, I fitted a 2-level random intercepts probit model using the xtprobit command with n independent variables:
    xtprobit y x1 x2... xn, re

    Next I used margins,
    margins , dydx(x1)

    Point estimates from this command are exactly the same in Stata 13.1 and in the current version of Stata 14. These are models where the Rho is estimated at .19, level 2 variance is significant. What gives?

    Similarly, in a subset of these data I estimate a linear model using xtreg. The outcome variable is logged so I ask margins to give me average marginal effects using exponentially transformed coefficients,
    margins , dydx(x) exp(exp(predict(xbu)))

    According to the predict help file xbu is supposed to be the effect including the random component, but Stata gives me the error that "predict option xbu not appropriate with margins"
    The command runs just fine when I ask for the prediction to be limited to the fixed effect only (i.e. "xb"). The margins help file even specifies that margins will only estimate the fitted values (xb) and that other options from the predict command, such as "u," are not available.

    Am I misunderstanding something? I imagine that the mistake is on my end but I just don't understand. The new product documentation sure makes it look like the random effects should be accounted for using margins but in my models it sure doesn't look like this is the case. Here's a link to the new product demo I'm referring to. http://www.stata.com/stata14/marginal-margins/

    Many thanks for any clarity you can provide.

  • #2
    predict after xtprobit and xtreg does not provide an option for computing
    predictions where the random effect is integrated out.

    predict after meprobit and meglm do provide this feature with the new
    marginal option.

    When margins is used with estimation results from these commands it will automatically
    assume the marginal option for predict unless the conditional(fixedonly)
    option is specified.

    The link Will provided above points out that this feature is available with for the following estimation
    commands:
    • melogit
    • meprobit
    • mecloglog
    • meoloit
    • meoprobit
    • mepoisson
    • menbreg
    • mestreg
    • meglm
    • gsem

    Comment


    • #3
      To be a bit more specific about how Jeff''s post affects Will. To fit the his model, Will at some point specified his panels using the xtset command.

      . xtset panelid

      Then will fit his model,

      . xtprobit y x1 x2... xn, re

      As Jeff pointed out, the [XT] suite of commands do not yet support predictions that are marginal w.r.t. the random effects. Will can, however, fit a random effects (intercepts) model that is "identical" to his xtprobit model using the multilevel modeling command meprobit,

      . meprobit y x1 x2 ... xn || panelid:

      After which, margins will automatically use marginal predictions.

      There is an equivalent [ME] estimation command for many [XT] estimation commands.

      I quoted identical, because the ME and XT commands use a different number of integration points by default during estimation and will thus can produce slightly different numerical results. You can make them identical by specifying the intpoints() option.

      From the above, it is clear that there is no statistical reason why many of the XT commands could not support marginal predictions. Rather, the marginal predictions are a bit more challenging to implement simply because of the way the XT commands were designed. I won't make any promises about when marginal predictions might appear in the XT suite.




      Comment


      • #4
        Dear Vince and Jeff,

        Many thanks for your clarification. Very useful indeed.

        I have an additional question.

        I am fitting a RE Poisson model (>xtpoisson, re<) and I have (fairly strong) reasons to prefer the default Gamma distribution of the random effect to the alternative >xtpoisson, re normal< option.

        Using STATA 14, I would like to compute the average marginal effect of a regressor using >margins< - obviously, 'incorporating' the random effect. The problem is that if I fit my model using >mepoisson Y X || panelid:<and then type >margins< as you suggest, the random effect, though fully 'incorporated', is assumed to be normally distributed.

        Is there an option for >mepoisson< that allows users to assume a Gamma distribution of the RE? If not, can you suggest another way around this problem?

        Many thanks in advance?

        Luca J. Uberti
        University of Otago, NZ

        Comment


        • #5
          Apologies for opening this older thread, Jeff, but can you confirm that this behavior has changed since at least Stata 16? I tested margins after melogit and xtlogit with the following model in Stata 16:

          Code:
          webuse towerlondon, clear
          tab difficulty, gen(diffc)
          melogit dtlm i.diffc1 i.diffc3 i.group || subject:
          Code:
          margins, dydx(diffc1 diffc3)
          
          Average marginal effects                        Number of obs     =        677
          Model VCE    : OIM
          
          Expression   : Marginal predicted mean, predict()
          dy/dx w.r.t. : 1.diffc1 1.diffc3
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
              1.diffc1 |   .3316323   .0401176     8.27   0.000     .2530032    .4102614
              1.diffc3 |  -.0737402   .0366981    -2.01   0.044    -.1456672   -.0018132
          ------------------------------------------------------------------------------
          Note: dy/dx for factor levels is the discrete change from the base level.
          And with xtlogit
          Code:
          xtlogit dtlm i.diffc1 i.diffc3 i.group, i(subject) re
          Code:
          margins, dydx(diffc1 diffc3)
          
          Average marginal effects                        Number of obs     =        677
          Model VCE    : OIM
          
          Expression   : Pr(dtlm=1), predict(pr)
          dy/dx w.r.t. : 1.diffc1 1.diffc3
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
              1.diffc1 |   .3316595   .0400791     8.28   0.000      .253106     .410213
              1.diffc3 |  -.0736689   .0366792    -2.01   0.045    -.1455588    -.001779
          ------------------------------------------------------------------------------
          Note: dy/dx for factor levels is the discrete change from the base level.
          These are very similar and would probably converge exactly if I upped the intpoints. But just want to make sure.


          Originally posted by Jeff Pitblado (StataCorp) View Post
          predict after xtprobit and xtreg does not provide an option for computing
          predictions where the random effect is integrated out.

          predict after meprobit and meglm do provide this feature with the new
          marginal option.

          When margins is used with estimation results from these commands it will automatically
          assume the marginal option for predict unless the conditional(fixedonly)
          option is specified.

          The link Will provided above points out that this feature is available with for the following estimation
          commands:
          • melogit
          • meprobit
          • mecloglog
          • meoloit
          • meoprobit
          • mepoisson
          • menbreg
          • mestreg
          • meglm
          • gsem

          Comment


          • #6
            In Stata 14, update 29oct2015 (Stata 14.1), item 16 in the whatsnew states that predict after xtlogit, re now allows predictions of the marginal probabilities, which is the probability of a positive outcome that is marginal with respect to the random effect (i.e. it gets integrated). As Erik shows in the example above, this is the default prediction used by margins.

            Comment

            Working...
            X