Announcement

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

  • margins + reg, nocons

    Hi,

    Does anyone knows, conceptually, why nocons affects margins calculations?



    Code:
    . webuse auto, clear
    (1978 automobile data)
    
    . reg price mpg i.foreign,nocons
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 72)        =     73.73
           Model |  2.3167e+09         2  1.1583e+09   Prob > F        =    0.0000
        Residual |  1.1311e+09        72  15710259.5   R-squared       =    0.6719
    -------------+----------------------------------   Adj R-squared   =    0.6628
           Total |  3.4478e+09        74  46592355.7   Root MSE        =    3963.6
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |   251.1707   26.42008     9.51   0.000     198.5032    303.8382
                 |
         foreign |
        Foreign  |   162.4989   1068.864     0.15   0.880    -1968.242     2293.24
    ------------------------------------------------------------------------------
    
    . margins ,at(mpg=(5500(250)6751)) atmeans
    
    Adjusted predictions                                        Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    ...
    6._at: mpg       =     6750
           0.foreign = .7027027 (mean)
           1.foreign = .2972973 (mean)
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |          .  (not estimable)
              2  |          .  (not estimable)
              3  |          .  (not estimable)
              4  |          .  (not estimable)
              5  |          .  (not estimable)
              6  |          .  (not estimable)
    ------------------------------------------------------------------------------
    
    
    . reg price mpg i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     14.07
           Model |   180261702         2  90130850.8   Prob > F        =    0.0000
        Residual |   454803695        71  6405685.84   R-squared       =    0.2838
    -------------+----------------------------------   Adj R-squared   =    0.2637
           Total |   635065396        73  8699525.97   Root MSE        =    2530.9
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
                 |
         foreign |
        Foreign  |   1767.292    700.158     2.52   0.014     371.2169    3163.368
           _cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
    ------------------------------------------------------------------------------
    
    . margins ,at(mpg=(5500(250)6751)) atmeans
    
    Adjusted predictions                                        Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    ...
    6._at: mpg       =     6750
           0.foreign = .7027027 (mean)
           1.foreign = .2972973 (mean)
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   -1605645   305118.5    -5.26   0.000     -2214034   -997255.6
              2  |   -1679193   319041.4    -5.26   0.000     -2315344    -1043043
              3  |   -1752742   332964.4    -5.26   0.000     -2416654    -1088830
              4  |   -1826291   346887.3    -5.26   0.000     -2517965    -1134618
              5  |   -1899840   360810.2    -5.27   0.000     -2619275    -1180405
              6  |   -1973389   374733.1    -5.27   0.000     -2720586    -1226192
    ------------------------------------------------------------------------------
    thanks.

  • #2
    The problem is that you specified i.foreign and -nocons- together. This left the model with no way to account for foreign = 0 observations. Consequently when -margins- encounters those, it doesn't know what to do and concludes that what you are asking for cannot be calculated.

    You need to account for the 0 level of foreign in your model somehow. Normally, the constant term does that. Without that, you need to include an indicator ("dummy") variable for it.

    Code:
    sysuse auto, clear
    
    reg price mpg ibn.foreign, nocons
    
    margins, at(mpg = (5500(250)6751)) atmeans
    You will note that this gives you the same results as -margins- after -reg price mpg i.foreign- (without -nocons-).

    Comment


    • #3
      a slight amendment - you should use the "hascons" option rather than the "nocons" option (since the two terms for foreign sum to a constant); this will not affect -margins- but will affect the regression summary statistics such as R2
      Last edited by Rich Goldstein; 19 Jul 2023, 18:59.

      Comment

      Working...
      X