Announcement

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

  • #16
    I have to disagree, whatever the common practice may be.

    If x is time-invariant within panels, then x is, in fact, an indicator for a subset of the panels. As such that x is colinear with the fixed-effects. That is why 1.x gets dropped. But it also means that -margins- cannot identify the effect of x vs the effects of the fixed effects in the model--it is mathematically unidentifiable due to the colinearity. It is really just the analog on the panel dimension of the fact that you cannot include a pre-post variable along with time fixed effects in the model if all of the panels that are treated get treated at the same time. In that case the pre-post variable becomes an indicator for a subset of the time fixed effects, and it, too, is colinear with them. And it is then impossible to distinguish an effect of pre-post from the time fixed effects themselves; and -margins- appropriately refuses to do so.

    This is really important. It is tempting in your situation to just use -lincom- to calculate the marginal effects of x in each time period here. And -lincom- will not hesitate to give you answers. But those answers are meaningless. In this situation, x constant over time within panels, the effect of x is truly, mathematically, unidentifiable in the context of panel fixed effects. If you force Stata to change the base category for the panel fixed effects and do it over, you will get different answers. That is how the colinearity rears its ugly head in this calculation. If you have seen papers published purporting to provide this kind of estimate, it just means that people have unwittingly published meaningless results--this happens all the time, even in top journals.
    Last edited by Clyde Schechter; 11 May 2023, 10:01.

    Comment


    • #17
      Wow Andrew! That indeed works -- in the nlswork dataset, and in my dataset. Thank you! I didn't think to do this because (a) my impression from the Jeff Pitblado explanation was that if 1.collgrad / 1.x was omitted from your regression, it necessarily incapacitated margins, and (b) the whole point of reghdfe is to include all your dummies in absorb().

      How did you even think of this? And do you have any idea why this works, when reghdfe ln_wage i.collgrad#i.year, absorb(idcode year) does not, and when xtreg ln_wage collgrad##i.year, fe does not? I'd really like to understand what's going on here.

      Additionally, this solution also drops one year interaction (from the regression and thus margins effects): the same year that is dropped from the year levels/dummies (68 in nls data). This is a metrics rather than coding question, but do you know why? It is theoretically necessary? It feels vaguely intuitive to me that a "base" interaction would be omitted, but when I think about the math, I'm not sure why. I think the best phrasing of my question would be -- how am I implicitly calculating the marginal effect of colgrad in 1968 through these fixed effects? I.e., the constant gives me the 1968 level, but what gives me the 1968 marginal effect of colgrad? (This question feels pressing, because without knowing the answer, I'm not sure I'm understanding the other marginal effects properly -- I don't think they are vis-a-vis the 1968 effect, but I'm not 100% sure.)

      I think a lot of the confusion here stemmed from me not posting a reproducible example at the beginning. This is my bad.
      Last edited by Leah Bevis; 11 May 2023, 10:20.

      Comment


      • #18
        Clyde, x is colinear with the fixed effects, but the *marginal effect* of x may still change over time. I know this feels counter-intuitive at first blush -- I recommend you read the REStat intro if you still feel skeptical. It may also help to realize that this is similar to what a differences in differences model is doing -- fixing out the location fixed effects (NJ vs. PA), fixing out the time effects (time 1 vs. time 2), but then looking at whether the change in NJ over time is different than the change in PA over time... that is, looking at whether the marginal effect of location changes over time, within a model with location fixed effects.

        Comment


        • #19
          And do you have any idea why this works, when reghdfe ln_wage i.collgrad#i.year, absorb(idcode year) does not, and when xtreg ln_wage collgrad##i.year, fe does not? I'd really like to understand what's going on here.
          I do not know exactly how margins works internally, but here are some things to consider. The following is an example of using the margins command to calculate the marginal effects by specifying the expression of the derivative:

          Model:

          \(\text{inv }= \beta_{0} + \beta_{1}\text{mv }+ \beta_{2}\text{ks }+ \beta_{3}\text{mv}\times\text{ks }+ \beta_{4}\text{L.x1 }+ \beta_{5}\text{D.x2 }+ \beta_{6}\text{D.x2}\times\text{c.L.x1 }+ \beta_{7}\text{mv}\times\text{D.x2 } + \beta_{8}\text{mv}\times\text{L.x1}\times\text{D.x 2} + u\)


          Expression:

          $$\frac{\partial{\text{invest}}}{\partial{\text{mv }}}= \beta_{1}+ \beta_{3}\text{ks }+\beta_{7}\text{D.x2 }+ \beta_{8}\text{L.x1}\times\text{D.x2}$$

          Code:
          webuse grunfeld, clear
          keep if company==1
          tsset time
          set seed 05112023
          forval i=1/2{
              gen x`i'= rnormal()
          }
          *USING MARGINS
          regress invest c.mvalue##c.kstock L.x1 D.x2 c.D.x2#c.L.x1 c.mvalue#c.D.x2 c.mvalue#c.L.x1#c.D.x2
          margins, dydx(mvalue)
          
          *MANUALLY USING MARGINS + EXPRESSION()
          gen mvks = c.mvalue#c.kstock
          gen mvDx2= c.mvalue#c.D.x2
          gen Lx1= L.x1
          gen Dx2= D.x2
          gen mvLx1Dx2= c.mvalue#c.L.x1#c.D.x2
          regress invest c.mvalue c.kstock c.mvks Lx1 Dx2 c.Dx2#c.Lx1 c.mvDx2 c.mvLx1Dx2
          local df= e(df_r)
          margins, expression(_b[c.mvalue]+_b[c.mvks]*ks +_b[c.mvDx2]*Dx2 + _b[c.mvLx1Dx2]*Lx1*Dx2) df(`df')
          Res.:

          Code:
          *USING MARGINS
          . margins, dydx(mvalue)
          
          Average marginal effects                                    Number of obs = 19
          Model VCE: OLS
          
          Expression: Linear prediction, predict()
          dy/dx wrt:  mvalue
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                mvalue |   .0833438   .0356836     2.34   0.042     .0038358    .1628519
          ------------------------------------------------------------------------------
          
          *MANUALLY USING MARGINS + EXPRESSION()
          
          . local df= e(df_r)
          
          . margins, expression(_b[c.mvalue]+_b[c.mvks]*ks +_b[c.mvDx2]*Dx2 + _b[c.mvLx1Dx2]*Lx1*Dx2) df(`df')
          warning: option expression() does not contain option predict() or xb().
          
          Predictive margins                                          Number of obs = 19
          Model VCE: OLS
          
          Expression: _b[c.mvalue]+_b[c.mvks]*ks +_b[c.mvDx2]*Dx2 + _b[c.mvLx1Dx2]*Lx1*Dx2
          
          ------------------------------------------------------------------------------
                       |            Delta-method
                       |     Margin   std. err.      t    P>|t|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                 _cons |   .0833438   .0356836     2.34   0.042     .0038358    .1628519
          ------------------------------------------------------------------------------

          Now with reghdfe, you need to be careful as it is possible to absorb some indicators which are part of the expression needed to compute the derivative. For example, something like below

          Code:
          reghdfe ln_wage i.collgrad#i.year, absorb(idcode year collgrad)
          [.] Here, we lack the coefficient on collgrad needed to compute the derivative. Perhaps there is a restriction that if an interaction exists but not the main effects, then margins does not compute the derivative. I do not know. Note that this is separate from the collinearity argument where the coefficients exist - in the matrix- but they just take the values zero.

          Additionally, this solution also drops one year interaction (from the regression and thus margins effects): the same year that is dropped from the year levels/dummies (68 in nls data). This is a metrics rather than coding question, but do you know why?
          I will have to run the regression again and get back to you on your second question.
          Last edited by Andrew Musau; 11 May 2023, 11:41.

          Comment


          • #20
            Clyde, x is colinear with the fixed effects, but the *marginal effect* of x may still change over time. I know this feels counter-intuitive at first blush
            Yes, of course the marginal effect of x may change over time and, for me, at least, there is nothing counter-intuitive about this. And it in no way contradicts what I'm saying.

            The point is, however, that the marginal effects of x cannot be estimated from a model that also includes the fixed effects for panel. The colinearity of x and the fixed effects makes it impossible to identify what attributable to x from what is attributable to the fixed effects. To get those marginal effects, you have to omit the panel fixed effects from the model. You have to estimate those marginal effects from a model that omits the panel fixed effects. This is linear algebra and there is no getting around it.
            Last edited by Clyde Schechter; 11 May 2023, 11:42.

            Comment


            • #21
              Additionally, this solution also drops one year interaction (from the regression and thus margins effects): the same year that is dropped from the year levels/dummies (68 in nls data). This is a metrics rather than coding question, but do you know why? It is theoretically necessary? It feels vaguely intuitive to me that a "base" interaction would be omitted, but when I think about the math, I'm not sure why. I think the best phrasing of my question would be -- how am I implicitly calculating the marginal effect of colgrad in 1968 through these fixed effects? I.e., the constant gives me the 1968 level, but what gives me the 1968 marginal effect of colgrad?
              With the omission of the coefficient on colgrad, the marginal effects are not identified. The coefficients on the interaction terms will change according to which indicator you choose to omit. So on the broader point, I agree with Clyde.
              Last edited by Andrew Musau; 11 May 2023, 12:03.

              Comment


              • #22
                Leah,

                Take a look at this example. I've done it emulating fixed-effects regression with OLS regression and panel indicator variables so that I can control exactly how the coliearities are handled.
                Code:
                webuse grunfeld, clear
                
                gen byte group = (company > 5)
                
                
                regress mvalue i.group#i.year i.year i.group
                margins, dydx(group) over(year) // WORKS
                
                regress mvalue i.group#i.year i.year i.group i.company
                margins, dydx(group) over(year) // FAILS
                margins, dydx(group) over(year) noestimcheck // APPEARS TO WORK
                
                //    NOW CHANGE THE BASE CATEGORY FOR COMPANY
                regress mvalue i.group#i.year i.year i.group ib5.company
                margins, dydx(group) over(year) noestimcheck // DIFFERENT RESULTS!
                The use of the -noesetimcheck- option in -margins- forces Stata to calculate the marginal effects using lincom on the appropriate coefficients. Notice that with a change in the base category of company, the marginal effects of group for the same years come out very different. These linear combinations of the coefficients are not marginal effects at all. In fact they aren't anything real: they are artifacts of the particular way that the colinearity between group and fixed effects is handled. To get the marginal effects of group in each year, you have to use the first model--the one which omits company effects.

                Comment


                • #23
                  Andrew -- thanks, yes, I just realized the same. I guess I knew this intuitively, but was having trouble putting it into math.

                  So if I'm understanding correctly, the marginal effects calculated in my reproducible example (or in my dataset) w/ your reghdfe ## code provide the CHANGE in marginal effect over time, vis-a-vis the (unidentifiable) marginal effect in the omitted time period. Agreed? This means marginal effects will change if you are looking at them relative to say, time period 1 vs. relative to the final time period. However, this seems to me a feature, not a bug. In event studies, for instance, the time-specific marginal effects are always relative to a baseline zero effect, generally placed the year before policy implementation. That's not wrong, one just has to bear in mind what the marginal effects mean.

                  Clyde, I find your example more perplexing, because like Andrew's example, your fully-manual regressions both omit 1 time period (the first, 1935) for both the interactions and the year levels. However, each margins command produces a marginal effect for *all* years including 1935. I don't understand how the 1935 effects would be calculated, and I would therefore guess that these marginal effects are "wrong"/meaningless in some fundamental way, whereas the marginal effects that Andrew provided (which did not require noestimcheck) are correct, but necessarily contextualized vis-a-vis the omitted interaction. But just guessing, as I find that output highly perplexing.

                  Comment


                  • #24
                    whereas the marginal effects that Andrew provided (which did not require noestimcheck) are correct, but necessarily contextualized vis-a-vis the omitted interaction
                    Well,I agree. But to me this is much more worrisome. What is this undisclosed context? I am pretty sure that the context is some covert constraint that identifies the model. But we don't know what that constraint is, and linear algebra tells us that a different constraint would provide different results for the marginal effects.

                    Comment


                    • #25
                      Clyde, I'm not sure I follow. I'm assuming that the "context" is as I stated -- we are seeing changes in marginal effect vis-a-vis the omitted marginal effect in the 1st time period. You say you agree with that, but then you also raise concerns about an undisclosed context... by context I think you mean base marginal effect? Feel free to exit this thread if you're tired of thinking about this, but just to note that I don't really understand your concern here. If I did, I would try to follow up with the Stata tech folks to be sure I fully understand these marginal effects being calculated under Andrew's method.
                      Last edited by Leah Bevis; 11 May 2023, 14:03.

                      Comment


                      • #26
                        As best I understand it, the results coming out of the margins command using the code in #15 are not the marginal effects of collgrad in each year. Rather they are the differences between those marginal effects and the indeterminate (i.e. not estimable) marginal effect of collgrad in 1968. In fact, when I compare them to the year-specific marginal effects calculated using -regress- (i.e. omitting the idcode fixed effects from the model), I can see that they are precisely that (well, modulo some tiny rounding errors here and there):
                        Code:
                        . regress ln_wage i.collgrad##i.year
                        
                              Source |       SS           df       MS      Number of obs   =    28,534
                        -------------+----------------------------------   F(29, 28504)    =    201.07
                               Model |  1107.61209        29  38.1935202   Prob > F        =    0.0000
                            Residual |   5414.2718    28,504   .18994779   R-squared       =    0.1698
                        -------------+----------------------------------   Adj R-squared   =    0.1690
                               Total |  6521.88388    28,533  .228573367   Root MSE        =    .43583
                        
                        -------------------------------------------------------------------------------
                              ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
                        --------------+----------------------------------------------------------------
                           1.collgrad |   .4627511    .046804     9.89   0.000      .371013    .5544891
                                      |
                                 year |
                                  69  |   .0895385   .0176932     5.06   0.000     .0548589     .124218
                                  70  |   .0672167   .0164366     4.09   0.000     .0350002    .0994332
                                  71  |   .0997394   .0161316     6.18   0.000     .0681207    .1313581
                                  72  |   .1179707   .0165069     7.15   0.000     .0856165    .1503249
                                  73  |   .1289467   .0160201     8.05   0.000     .0975465     .160347
                                  75  |   .1208245   .0158787     7.61   0.000     .0897016    .1519475
                                  77  |   .1838134   .0160143    11.48   0.000     .1524245    .2152022
                                  78  |   .2316857    .016439    14.09   0.000     .1994646    .2639069
                                  80  |   .2414506    .016692    14.47   0.000     .2087334    .2741678
                                  82  |   .2301258   .0162282    14.18   0.000     .1983177    .2619338
                                  83  |   .2640497   .0164751    16.03   0.000     .2317578    .2963416
                                  85  |    .317086   .0163297    19.42   0.000     .2850789    .3490931
                                  87  |   .3256101   .0162239    20.07   0.000     .2938104    .3574097
                                  88  |    .368006   .0160474    22.93   0.000     .3365523    .3994596
                                      |
                        collgrad#year |
                                1 69  |   .0213055   .0687739     0.31   0.757    -.1134945    .1561056
                                1 70  |  -.0736689    .061523    -1.20   0.231    -.1942568     .046919
                                1 71  |  -.0230467   .0593321    -0.39   0.698    -.1393403    .0932469
                                1 72  |  -.0600206   .0588738    -1.02   0.308    -.1754161    .0553748
                                1 73  |  -.1230566   .0559013    -2.20   0.028    -.2326258   -.0134875
                                1 75  |  -.1287874   .0538471    -2.39   0.017    -.2343303   -.0232446
                                1 77  |  -.1246688   .0524826    -2.38   0.018    -.2275371   -.0218005
                                1 78  |  -.1039252   .0527091    -1.97   0.049    -.2072375   -.0006129
                                1 80  |  -.0930635   .0529799    -1.76   0.079    -.1969067    .0107797
                                1 82  |  -.0503205    .052359    -0.96   0.337    -.1529466    .0523056
                                1 83  |  -.0432334   .0523428    -0.83   0.409    -.1458277     .059361
                                1 85  |  -.0098713   .0519922    -0.19   0.849    -.1117785     .092036
                                1 87  |  -.0143531   .0517294    -0.28   0.781    -.1157452     .087039
                                1 88  |  -.0301393   .0515268    -0.58   0.559    -.1311342    .0708557
                                      |
                                _cons |   1.410062   .0121723   115.84   0.000     1.386203     1.43392
                        -------------------------------------------------------------------------------
                        
                        . margins, dydx(collgrad) over(year)
                        
                        Average marginal effects                                Number of obs = 28,534
                        Model VCE: OLS
                        
                        Expression: Linear prediction, predict()
                        dy/dx wrt:  1.collgrad
                        Over:       year
                        
                        ------------------------------------------------------------------------------
                                     |            Delta-method
                                     |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
                        -------------+----------------------------------------------------------------
                        0.collgrad   |  (base outcome)
                        -------------+----------------------------------------------------------------
                        1.collgrad   |
                                year |
                                 68  |   .4627511    .046804     9.89   0.000      .371013    .5544891
                                 69  |   .4840566   .0503908     9.61   0.000     .3852882    .5828249
                                 70  |   .3890822   .0399307     9.74   0.000     .3108161    .4673482
                                 71  |   .4397044   .0364647    12.06   0.000     .3682317     .511177
                                 72  |   .4027304   .0357143    11.28   0.000     .3327288    .4727321
                                 73  |   .3396945    .030567    11.11   0.000     .2797818    .3996072
                                 75  |   .3339636   .0266251    12.54   0.000     .2817772    .3861501
                                 77  |   .3380823   .0237446    14.24   0.000     .2915418    .3846228
                                 78  |   .3588258   .0242411    14.80   0.000     .3113121    .4063396
                                 80  |   .3696876   .0248246    14.89   0.000     .3210303    .4183449
                                 82  |   .4124305   .0234702    17.57   0.000     .3664279    .4584332
                                 83  |   .4195177    .023434    17.90   0.000     .3735859    .4654495
                                 85  |   .4528798   .0226402    20.00   0.000      .408504    .4972556
                                 87  |    .448398     .02203    20.35   0.000     .4052182    .4915777
                                 88  |   .4326118   .0215499    20.07   0.000      .390373    .4748505
                        ------------------------------------------------------------------------------
                        Note: dy/dx for factor levels is the discrete change from the base level.
                        So, I am comfortable, now, that I understand what they are. But they are certainly not the marginal effects. And if you could control the way -reghdfe- chose to constrain the model to use some other year, instead of 1968, then the results would be different (although, again, differences between results would be the same.)

                        So it boils down to whether those differences from a non-estimable marginal effect are useful and interesting. Perhaps they are: that's substantive question, not a statistical one. Even if they are, though, it's important not to speak about them as if they really were marginal effects. The real marginal effects are the ones coming out of -regress-: those are not artifacts of any choice of constraint on an unidentified model. They are "the real McCoy."

                        Comment


                        • #27
                          Thanks again for the help! And yes, this is what I understood these effects to be -- not the marginal effects themselves, but the *change* in marginal effect over time. In my case this is interesting, as it often is, in event studies. In fact, this is just a robustness check for me, but it's the central ID strategy of this paper here, which I'm mimicking (theta represents that change in equations 1-3): http://academics.wellesley.edu/Econo...try%202022.pdf
                          Last edited by Leah Bevis; 15 May 2023, 15:29.

                          Comment

                          Working...
                          X