Announcement

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

  • Marginal Effects at Means After Fixed Effects Regression

    Hi all, I have a problem with margins after having run Correia's (2017) reghdfe command.

    First of all, here are my data:

    Code:
    input float(COVID yearmonth Acquirername grossKformationEuroArea exports_percent_GDP_Euroarea target_in_US)
    0 661 805  500294.3 45.17 1
    0 661 336  500294.3 45.17 1
    0 661 413  500294.3 45.17 1
    0 662 465  500294.3 45.17 1
    0 662  35  500294.3 45.17 0
    0 662 374  500294.3 45.17 1
    0 662 830  500294.3 45.17 1
    0 662 576  500294.3 45.17 1
    0 662 690  500294.3 45.17 1
    0 662 575  500294.3 45.17 1
    0 662 444  500294.3 45.17 1
    0 662 488  500294.3 45.17 1
    0 662  66  500294.3 45.17 1
    0 662 355  500294.3 45.17 1
    0 662 391  500294.3 45.17 1
    0 662 405  500294.3 45.17 1
    0 663 827 539951.94 45.17 1
    0 663 350 539951.94 45.17 1
    0 663 329 539951.94 45.17 1
    0 663 410 539951.94 45.17 0
    0 663 336 539951.94 45.17 0
    0 663 777 539951.94 45.17 1
    0 663  45 539951.94 45.17 1
    0 663 479 539951.94 45.17 1
    0 663 619 539951.94 45.17 0
    0 663 725 539951.94 45.17 1
    0 663 488 539951.94 45.17 1
    0 663 170 539951.94 45.17 1
    0 664 426 539951.94 45.17 0
    0 664 665 539951.94 45.17 0
    0 664 619 539951.94 45.17 1
    0 664 700 539951.94 45.17 0
    0 664 488 539951.94 45.17 1
    0 664 171 539951.94 45.17 0
    My data are xtset:
    Code:
    xtset AcquirorName yearmonth
    I have run the following regression using Correia's (2015) reghdfe command:

    Code:
    reghdfe mean_ValueofTransactionmil grossKformationEuroArea exports_percent_GDP_Euroarea target_in_US COVID mean_MainRefOperatRate_monthly BroadREEREuroArea mean_SP500Returns_monthly CPAllItemsEuroArea ECBAssetsMoMchangeavg GDPEuroareaIndexMonthly euro_area_corporate_tax_rate c.grossKformationEuroArea#1.COVID c.BroadREEREuroArea#1.COVID c.mean_SP500Returns_monthly#1.COVID c.CPAllItemsEuroArea#1.COVID c.ECBAssetsMoMchangeavg#1.COVID c.GDPEuroareaIndexMonthly#1.COVID, absorb(Acquirername quarter) cluster(Acquirername)
    I am interested in the marginal effect at means of COVID. Firstly I ran:
    Code:
    margins COVID
    and got

    Code:
    Predictive margins                                         Number of obs = 687
    Model VCE: Robust
    
    Expression: Linear prediction, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           COVID |
              0  |          .  (not estimable)
              1  |   944.9654    205.082     4.61   0.000     543.0121    1346.919
    ------------------------------------------------------------------------------
    If in the regression I replace 1.COVID by i.COVID in the interaction terms, predictive margins are not estimable for both values of COVID.

    Finally, the most interesting:

    Code:
    margins, dydx(COVID) atmeans
    And the error message:
    Code:
    invalid dydx() option;
    variable COVID may not be present in model as factor and continuous predictor
    Please could someone let me know what I've done wrong?
    Last edited by Maxence Morlet; 04 Feb 2022, 11:17.

  • #2
    Maxence:
    I'm not sure I got you right.
    Maybe you are interested in something along the following toy-example:
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . regress price i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =      0.17
           Model |  1507382.66         1  1507382.66   Prob > F        =    0.6802
        Residual |   633558013        72  8799416.85   R-squared       =    0.0024
    -------------+----------------------------------   Adj R-squared   =   -0.0115
           Total |   635065396        73  8699525.97   Root MSE        =    2966.4
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |
        Foreign  |   312.2587   754.4488     0.41   0.680    -1191.708    1816.225
           _cons |   6072.423    411.363    14.76   0.000     5252.386     6892.46
    ------------------------------------------------------------------------------
    
    . margins, over(foreign) at(foreign=(0 1))
    
    Adjusted predictions                                        Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    Over:       foreign
    1._at: 0.foreign
               foreign = 0
           1.foreign
               foreign = 0
    2._at: 0.foreign
               foreign = 1
           1.foreign
               foreign = 1
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
     _at#foreign |
     1#Domestic  |   6072.423    411.363    14.76   0.000     5252.386     6892.46
      1#Foreign  |   6072.423    411.363    14.76   0.000     5252.386     6892.46
     2#Domestic  |   6384.682   632.4346    10.10   0.000     5123.947    7645.417
      2#Foreign  |   6384.682   632.4346    10.10   0.000     5123.947    7645.417
    ------------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Hi Maxence,

      The issue is that COVID appears in the covariate list as a categorical variable and a continuous covariate. Here is another example that triggers the same issue.

      Code:
      sysuse auto, clear 
      
      regress mpg foreign i.foreign#c.trunk
      
      margins foreign
      margins, dydx(*)
      To solve it, I enter foreign always as a categorical variable.

      Code:
      sysuse auto, clear 
      
      regress mpg i.foreign i.foreign#c.trunk
      
      margins foreign
      margins, dydx(*)
      Notice that the first case, -margins foreign-, always works. -margins VAR- is looking for a the categorical variable -VAR- within the list of categorical variables. In the second case it looks for the variable with the name VAR in the list of continuous and categorical variables.

      Comment


      • #4
        Dear both,

        Thank you very much for your help.

        @Enrique: thanks for your clarification!

        I'm now no longer getting the error I mentioned in the message above.

        I re-ran the regression:
        Code:
        reghdfe mean_ValueofTransactionmil grossKformationEuroArea exports_percent_GDP_Euroarea target_in_US i.COVID mean_MainRefOperatRate_monthly BroadREEREuroArea mean_SP500Returns_monthly CPAllItemsEuroArea ECBAssetsMoMchangeavg GDPEuroareaIndexMonthly euro_area_corporate_tax_rate c.grossKformationEuroArea#i.COVID c.BroadREEREuroArea#i.COVID c.mean_SP500Returns_monthly#i.COVID c.CPAllItemsEuroArea#i.COVID c.ECBAssetsMoMchangeavg#i.COVID c.GDPEuroareaIndexMonthly#i.COVID, absorb(Acquirername quarter) cluster(Acquirername)
        and although no regressors were dropped due to multicollinearity, I got the following:

        Code:
        margins, dydx(COVID)
        
        Average marginal effects                                   Number of obs = 687
        Model VCE: Robust
        
        Expression: Linear prediction, predict()
        dy/dx wrt:  1.COVID
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
             1.COVID |          .  (not estimable)
        ------------------------------------------------------------------------------
        Note: dy/dx for factor levels is the discrete change from the base level.
        Is there something else I've done wrong? Or is there an econometric reason behind it?

        Many thanks in advance!
        Maxence
        Last edited by Maxence Morlet; 04 Feb 2022, 14:10.

        Comment


        • #5
          Hi Maxence,

          -margins- has an estimability check and an option to turn it off -noestimcheck-. There is a discussion about it on the eight page of the documentation https://www.stata.com/manuals/rmargins.pdf and some further discussion after this. You can turn off the estimability check if you are confident that none of the issues discussed are pertinent to you. Turning off the estimability check is not a "solution" but you are the best judge of this.

          Comment

          Working...
          X