Announcement

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

  • Margins with effects

    I am estimating an equation
    \[
    Y_{ist} = \alpha D_{ist} + \beta \cdot x_{ist} + \gamma_s + \lambda_t + \delta_i + \varepsilon_{ist},
    \]
    where ist denotes individual, state and time. I am estimating it with

    Code:
    xtset i t
    xtreg Y D `xx' i.s i.t, fe
    The macro `xx' is a list of covariates. I am now trying to get the mean prediction but setting D to zero:
    \[
    \mathbb{E}[Y_{ist} \mid D_{ist} = 0]
    \]
    I want to prediction to include the effects \delta_i. Notice that margins, at(D = 0) gives me the mean prediction without the effects \delta_i.
    Last edited by Miguel Olivo-Villabrille; 12 Jul 2018, 20:46.

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    I don't understand what \delta.i means. Are you asking for the effect if D=0 and D=1? that just takes an at statement - see the margins documentation.

    Comment


    • #3
      Hi Phil,

      delta_i is the individual-specific fixed-effect. Similarly, gamma_s and lambda_t are are state-specific, and time-specific fixed-effects.

      Like I said, what I want to get is the mean prediction of Y given that D = 0. I could get the prediction with
      Code:
      predict, xbu
      and I can work with that to get the mean prediction, but I was wondering if there is a Stata command that would give me what I am after, along with perhaps confidence intervals. Like you mention, I could use
      Code:
      margins, at(D = 0)
      but like I mentioned, that ignores the individual effects delta_i, that is, it gives the expression
      \[
      \mathbb{E}[Y_{ist} \mid D_{ist} = 0, \delta_i = 0].
      \]
      Last edited by Miguel Olivo-Villabrille; 15 Jul 2018, 00:07.

      Comment


      • #4
        Since this is a linear model, you can re-run it as:

        Code:
        regress Y D `xx' i.s i.t i.i
        after which
        Code:
        margins, at(D = 0)
        will give you what you want, if I understand you correctly.

        Comment


        • #5
          The problem with that solution
          Code:
          regress Y D `xx' i.s i.t i.i
          is that when there are a large number of individuals, it becomes unfeasible. I could use areg, but with that I can't use the "trick" below to obtain the mean prediction I'm after.

          But more fundamentally, consider
          Code:
          webuse nlswork
          xtset idcode year
          xtreg ln_w grade age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure c.tenure#c.tenure 2.race i.not_smsa i.south i.year, fe
          keep if e(sample)
          
          margins, at(not_smsa = 0 south = 0)
          
          Predictive margins                              Number of obs     =     28,091
          Model VCE    : Conventional
          
          Expression   : Linear prediction, predict()
          at           : not_smsa        =           0
                         south           =           0
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                 _cons |   1.726847   .0053209   324.54   0.000     1.716418    1.737276
          ------------------------------------------------------------------------------
          
          clonevar not_smsa2 = not_smsa
          clonevar south2 = south
          replace not_smsa = 0
          replace south = 0
          predict xb, xb
          predict xbu, xbu
          sum xb xbu
          
          
              Variable |        Obs        Mean    Std. Dev.       Min        Max
          -------------+---------------------------------------------------------
                    xb |     28,091    1.726847    .1805905   1.258244   2.484918
                   xbu |     28,091    1.677103    .3975748          0    3.98918
          Notice that margins gives the answer for xb, rather than xbu. Why is that? and how can I obtain the mean prediction given not_smsa = 0 and south = 0 with fixed-effects?

          Comment


          • #6
            Notice that margins gives the answer for xb, rather than xbu. Why is that?
            Well, -help xtreg postestimation- says that the default prediction for -margins- after -xtreg- is based on xb. It goes even further and says that -xbu- is not permitted, even though -predict, xbu- does exist. I do not know why. Usually when Stata doesn't support some calculation there is a good reason why it can't or shouldn't be done. But I can't think of such a reason in this instance.

            and how can I obtain the mean prediction given not_smsa = 0 and south = 0 with fixed-effects?
            Well, you have in fact already done it. Your own calculations , copied here, do exactly that:
            Code:
            clonevar not_smsa2 = not_smsa
            clonevar south2 = south
            replace not_smsa = 0
            replace south = 0
            // predict xb, xb
            predict xbu, xbu
            summ /*xb*/ xbu

            Comment


            • #7
              I mean to ask how I can do it with margins, so that I can get standard errors and confidence intervals as side effects, hehe...

              Comment


              • #8
                OK, I see. Well, I have to say I'm stumped here. I can't think of anything other than the -regress... i.i ...- approach, which your data set is not compatible with.

                Comment


                • #9
                  I found this answer:
                  https://www.stata.com/support/faqs/s...on-unsuitable/

                  It seems I can use
                  Code:
                  margins, at(not_smsa = 0 south = 0) predict(xbu) force
                  Last edited by Miguel Olivo-Villabrille; 15 Jul 2018, 22:47.

                  Comment


                  • #10
                    Thank you.

                    Comment

                    Working...
                    X