Announcement

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

  • xtpqml interaction with marginsplot

    Hello Stata Users,

    I am trying to run an xtpqml model with two continuous variables and their interaction (i.e. y = a + b + ab). Typically in a regression analysis I would use a factor variable interaction (i.e. y = c.a##c.b) however xtpqml doesn't allow for factor variable interactions. To run the model I have hardcoded the interaction as a new variable (i.e. gen ab = a*b).

    The problem is when I want to create an interaction plot. I have been using margins and marginsplot for interactions (see http://www.ats.ucla.edu/stat/stata/faq/conconb12.htm) but because my interaction variable is hardcoded I am running into problems. Do you have suggestions on how to deal with this?

    Thanks,
    Daniel

  • #2
    You are using package xtpqml from http://fmwww.bc.edu/RePEc/bocode/x (please see the Advice Guide on explaining user-written software). It long predates marginsplot so my guess is that you have to custom-code this yourself. Just a guess....

    Comment


    • #3
      The online help for xtpqml states that it is simply a wrapper for xtpoisson that computes robust standard errors.

      Robust variance estimation was added to xtpoisson in Stata 12, so if you have access to Stata 12 or later you can just use xtpoisson directly with vce(robust) and the factor variable interaction notation then use margins and marginsplot.

      Comment


      • #4
        Very helpful. Thanks Jeff.

        I confirmed that results from xtpqml and xtpoisson, robust are the same standard errors.

        Here is a follow up question. When running margins and marginsplot with poisson the y axis says "number of events predicted". However when running the same with xtpoisson I get "linear prediction" along the y axis. Any reason for this difference in labeling?

        Comment


        • #5
          The margins command works with the default prediction for the current estimation results.

          For poisson the default prediction is number of events (n).
          For xtpoisson the default prediction is the linear prediction (xb).

          You can control what margins works with by specifying the predict() option.

          While not exactly the same thing as the predicted number of events after poisson, predict after xtpoisson has option nu0 (nu zero) for predicting the number of events assuming a zero random effect.

          Here is a simple example based on the one in the help file for xtpoisson.
          Code:
          webuse ships
          xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, exp(service)
          margins, predict(nu0)
          If you are willing to model the random effect using the normal distribution, there is a simple formula for computing the expected number of events marginally with respect to the random effect. Lets write the linear predictor for the outcome as

          \[
          x\beta + u
          \]

          where \(u\) is the random effect, assumed to be normally distributed with zero mean and variance \(\sigma^2\).

          Conditionally on \(x\) and \(u\), the outcome's expected number of events is given by

          \[
          \exp(x\beta + u)
          \]

          The the expected number of events, marginally with respect to \(u\) is thus given by

          \[
          E[\exp(x\beta+u)] = \exp\left(x\beta + \frac{1}{2}\sigma^2\right)
          \]

          You can specify this formula using the expression() option of margins.

          The following is based on an example in the help file for xtpoisson.
          Code:
          webuse ships
          xtpoisson accident op_75_79 co_65_69 co_70_74 co_75_79, exp(service) normal
          margins, expression(exp(xb() + exp(_b[lnsig2u:_cons])/2))
          Last edited by Jeff Pitblado (StataCorp); 01 Apr 2014, 16:16.

          Comment

          Working...
          X