Announcement

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

  • Using margins with vce(unconditional) option after xtreg

    I have a balanced panel dataset (t=Year and i=Individual denoted by Year and IndvID respectively) and the following econometric model

    Y = b1*var1 + b2*var2 + b3*var1*var2 + b4*var4 + fe + epsilon

    am estimating the following fixed-effects regression

    Code:
    xi: xtreg Y var1 var2 c.var1#c.var2 var3 i.Year, fe vce(cluster IndvID)
    (all variables are continuous except for the Year dummies being created by i.Year)

    I want STATA to derive/report the overall marginal effect of var1 and var2 on the outcome Y:

    dY/dvar1 = b1 + b3*var2

    dY/dvar2 = b2 + b3*var1

    Because I estimate the fixed-effect regression using robust standard errors, I want to make sure the marginal effect are being computed taking into account the same heterogeneity that the clustered standard errors correct for. My understanding is that this can be achieved using the
    vce(unconditional) option of the margins command. However, after running the above regression, when I run the command

    Code:
    margins, dydx(var1) vce(unconditional)
    I get the following error:

    xtreg is not supported by margins with the vce(unconditional) option
    Am I missing something obvious here or am I not going about this correctly? How can I cluster standard errors for margin estimates computed for STATA rather than using the Delta Method default, which won't do this?

    Thanks in advance,

    -Mark


  • #2
    I don't know if it has anything to do with your error, but don't use the xi: prefix. It isn't necessary and may just confuse margins.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Richard, I forgot to mention that I'm also running a linear time trend in the regression:

      Code:
       
       xi: xtreg Y var1 var2 c.var1#c.var2 var3 i.Year i.IndvID|Year, fe vce(cluster IndvID)
      So I think I need to use the xi: prefix to get STATA to generate the linear time trend appropriately. Also the error STATA gives refers specifically to the xtreg command.

      Comment


      • #4
        Not 100% sure, but I suspect you still don't need xi. See -help factor variables- . If you type -help xi- , you will see that it says xi usually isn't necessary anymore.

        I agree that this probably isn't the cause of your problem. Then again I am not sure it is a problem. Maybe only delta is legit. One of my ongoing complaints about the margins help is that it is not customized for each command, hence it is hard to tell what options are legitimate for a specific command and which are not.

        In this case it may be that Stata is smarter than us (and knows that vce(unconditional) would be wrong) or it may be that Stata is not doing something it should or could. Unless somebody really really really smart about these things chimes in, you may wish to write to Stata Tech Support.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Mark should take Richard's advice. The xi prefix is only necessary for estimation commands that
          do not support factor variables, and margins will be very difficult to use with estimation results
          produced using xi instead of factor variables notation.

          For use with margins afterward, the model should be specified without xi:
          Code:
          xtreg Y var1 var2 c.var1#c.var2 var3 i.Year, fe vce(cluster IndvID)
          However, Mark mentions that he wants to run a linear time trend. It is my understanding that this means
          he really wants to treat year as a continuous linear predictor, with means drop the i. operator from
          the Year variable:
          Code:
          xtreg Y var1 var2 c.var1#c.var2 var3 Year, fe vce(cluster IndvID)
          Regarding the error from margins:

          margins with option vce(unconditional) requires that predict allows the scores
          option, and that the scores can be used to compute a linearize variance estimator.

          predict after xtreg, fe does not produce the required scores.

          Mark stated his reason for using vce(unconditional):
          Because I estimate the fixed-effect regression using robust standard errors, I want to make sure the marginal effect are being computed taking into account the same heterogeneity that the clustered standard errors correct for. My understanding is that this can be achieved using the
          vce(unconditional) option of the margins command.
          For variance estimation, the delta method only treats the predictors as fixed while still using the
          clustered/robust variances estimates of the model parameters. Mark could look at the marginal
          effects of var1 at specific values of var2 using margins' at() option. For example
          Code:
          margins , dydx(var1) at(var2=5(5)25)
          In this case, using vce(unconditional) would yield the same variance estimates as the
          default delta method.

          Provided the number of individuals in Mark's dataset isn't too close to 11,000, he could
          use regress instead of xtreg.
          Code:
          regress Y var1 var2 c.var1#c.var2 var3 Year i.IndvID, vce(cluster IndvID)
          margins , dydx(var1) vce(unconditional)

          Comment


          • #6
            Hi Jeff,

            Thanks for clarifying. So my understanding is that the vce(unconditional) option will give you the correct robust (clustered) standard errors under the delta method as long as the regression model was run using clustered standard errors?

            Regarding the linear time trend, I meant that I want the linear time trend to have different intercepts for each Individual in my panel dataset. This would be accomplished by adding the regressor DIndvID*Year. Where DIndvID is a dummy for the individual and Year is just the continuous variable for the year (linear time trend for year). My understanding is that the syntax for making Stata generate this correctly is
            Code:
            i.Indv|Year
            and Stata only recognizes this syntax if I use the xi: prefix. Is there another way to do this without the xi: prefix?

            Comment


            • #7
              No. The syntax to generate the interaction between DIndvID and Year, the former a categorical variable and the latter continuous, is:

              Code:
              i.DIndvID#c.Year
              Note that:
              1. The c. is mandatory to prevent year from being treated as categorical.
              2. The i. is optional: Stata assumes variables adjacent to # are categorical unless otherwise designated.
              3. Not only do you not need to use the xi: prefix, you will get things very messed up if you do use it.
              4. This notation leaves you responsible for including the main effects of DIndvID and Year in the model. To automatically include them without having to specify them explicitly, use ## in place of #. (However, in fixed effects regression, if one of these variables does not vary within the clusters, then its main effect should be omitted.)

              You really should pretty much forget about xi altogether. There are only a handful of situations where it is still useful, and most of them involve fairly archaic statistical procedures. And it can easily get in the way and mess things up, as here.

              Comment


              • #8
                Hi Clyde,

                Thanks for your suggestion. To be clear, in addition to controlling for the usual fixed effect (identified by the IndvID variable) I want a "Year fixed effect" (identified by the covariate i.Year) and to allow the intercept on a linear time trend to be different for different IndvID's (identified by the covariate i.IndvID|Year).

                With regards to the linear time trend, I want all interactions and main effects of Year but NOT the main effect of IndvID because IndvID is the variable identifying the individual level in the panel data, which is essentially, the fixed effect. I know for sure that the syntax

                Code:
                xi: Y var1 var2 c.var1#c.var2 var3 i.Year i.IndvID|Year
                will do this because it's stated explicitly in the xi: help file. If I use your syntax, won't I need to do something like this

                Code:
                Y var1 var2 c.var1#c.var2 var3 i.Year  i.IndvID#Year Year
                That is, include the main effect of Year as well? I'm just not clear on, without using xi: how to make sure the main effect of DIndvID is NOT included while the main effect and all interactions of Year ARE included.

                Thanks

                Comment


                • #9
                  I am confused by "intercept on a linear time trend." Aren't you allowing the slope for year to differ for every individual? And if, say, you have a 1000 panel ids, doesn't that mean you'll be adding a 1000 variables to the model? I am sure you do not want to use xi (at least not if you want to run margins afterward) but I am unclear what you want the model to be.
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  Stata Version: 17.0 MP (2 processor)

                  EMAIL: [email protected]
                  WWW: https://www3.nd.edu/~rwilliam

                  Comment


                  • #10
                    This is my best guess as to what you want:

                    Code:
                    xtreg Y c.var1 c.var2 c.var1#c.var2 c.var3 i.Year c.Year i.IndvID#c.Year, fe vce(cluster IndvID)
                    I added c. and i. even when not necessary just to be clear on whether a variable was being treated as continuous or categorical.

                    I'm just not clear on, without using xi: how to make sure the main effect of DIndvID is NOT included
                    i.IndvID is not included in my code, so it is not being included in the model.

                    while the main effect and all interactions of Year ARE included
                    c.Year and i.IndvID#c.Year are included in the code.

                    Again, I wonder if this is what you really want. You have both i.Year and c.Year in your model. And, for every individual in your panel, i.IndvID#c.Year is going to add another variable. And it won't be an intercept for linear time trend that differs for each case, it will be a slope for year that differs for every case. But, if this is what you really want, I think the above code does it.

                    Also, I hate to do this for the 500th time, but the following hopefully makes clear why you want to use i. notation, rather than generate dummies/interactions yourself (or have xi generate dummies & interactions for you):

                    http://www3.nd.edu/~rwilliam/stats/Margins01.pdf

                    EDIT: I think my proposed code is the same as Clyde's proposed code, but he can correct me if I am wrong about that.
                    Last edited by Richard Williams; 05 Sep 2014, 21:49.
                    -------------------------------------------
                    Richard Williams, Notre Dame Dept of Sociology
                    Stata Version: 17.0 MP (2 processor)

                    EMAIL: [email protected]
                    WWW: https://www3.nd.edu/~rwilliam

                    Comment


                    • #11
                      Hi Richard,

                      Thanks for the link. Your code above is essentially what I ended up doing. I also checked and it makes no difference if I do it this way or use xi: the way I was using it before either in the model estimation or in the margins calculations. However, I suppose I should update my Stata usage and abandon xi: if it has become outdated. The econometric model I am estimating is

                      Code:
                      Revenuesit = di*t + t + dt + di + beta*Xit + eit
                      Where di is the individual firm's fixed effect controlling for unobservable variables that affect firm i's revenues that are constant over time, dt is a year fixed effect that controls for unobservables that affect every firm's revenue in a given year that don't vary over time and (di*t + t )is a "linear time trend" that allows each firm to have a different time trends (intercept and slope) in revenues, beta is a vector of parameters and Xit is a vector of control variables. Given this is what I want, does the following code accomplish this

                      Code:
                      xtreg Revenues i.IndvID#c.Year Year i.Year Conrols, fe robust
                      because the xi syntax I was using before

                      Code:
                      xi: xtreg Revenues i.IndvID|Year i.Year Controls, fe vce(cluster IndvID)
                      gives the same thing right?

                      Thanks for your help.

                      Comment


                      • #12
                        The use of xi versus using factor variable notation is primarily important for using margins afterwards, not for the coefficients from the estimation command itself. If you generate the dummies yourself (or let xi generate them) margins can screw up, because it doesn't know how the dummies are inter-related. And even if it didn't screw up in your specific case it could and would in others, as my handout shows.

                        I am not sure why you are using robust in one command (robust is also outdated but still working syntax) and vce(cluster IndvID) in the other. I would think you'd want the latter, but maybe it doesn't matter in this case.

                        Edit: The documentation for xtreg says "Specifying vce(robust) is equivalent to specifying vce(cluster panelvar); see xtreg, fe in Methods and formulas."
                        Last edited by Richard Williams; 05 Sep 2014, 22:28.
                        -------------------------------------------
                        Richard Williams, Notre Dame Dept of Sociology
                        Stata Version: 17.0 MP (2 processor)

                        EMAIL: [email protected]
                        WWW: https://www3.nd.edu/~rwilliam

                        Comment

                        Working...
                        X