Announcement

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

  • Obtaining same coefficients on dummy variables from xtreg and reg

    Similar questions have popped up several times on the forum but I couldn't find an answer to what I am looking for...

    I run simple regression with product code dummies and I get coeffcients on product code:

    Code:
    reg y x i.product_code, noconstant
    But I have too many products and therefore too many product code dummies. Even I set mat size to be 11.000, it is not enough... Instead I want to use xtreg and obtain the same coeffcients. I know I could do:

    Code:
    xtset product_code
    xtreg y x, fe
    predict y_hat, u
    But it does not give the same results. Is there a way of obtaining true coeffcients on product code dummies?
    Last edited by Erdem Yilmaz; 09 Jul 2018, 09:30.

  • #2
    Erdem:
    have you tried using -areg- instead of -regress-?
    Code:
    . use "http://www.stata-press.com/data/r15/nlswork.dta"
    . areg ln_wage i.idcode age if idcode<=5, abs(idcode) vce(cluster idcode)
    note: 2.idcode omitted because of collinearity
    note: 3.idcode omitted because of collinearity
    note: 4.idcode omitted because of collinearity
    note: 5.idcode omitted because of collinearity
    
    Linear regression, absorbing indicators         Number of obs     =         61
    Absorbed variable: idcode                       No. of categories =          5
                                                    F(   1,      4)   =       0.64
                                                    Prob > F          =     0.4676
                                                    R-squared         =     0.3281
                                                    Adj R-squared     =     0.2670
                                                    Root MSE          =     0.3029
    
                                     (Std. Err. adjusted for 5 clusters in idcode)
    ------------------------------------------------------------------------------
                 |               Robust
         ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          idcode |
              2  |          0  (omitted)
              3  |          0  (omitted)
              4  |          0  (omitted)
              5  |          0  (omitted)
                 |
             age |   .0151366   .0188793     0.80   0.468    -.0372807    .0675539
           _cons |   1.374028   .5515226     2.49   0.067    -.1572444      2.9053
    ------------------------------------------------------------------------------
    
    . xtreg ln_wage age if idcode<=5, fe
    
    Fixed-effects (within) regression               Number of obs     =         61
    Group variable: idcode                          Number of groups  =          5
    
    R-sq:                                           Obs per group:
         within  = 0.0899                                         min =         11
         between = 0.0141                                         avg =       12.2
         overall = 0.0408                                         max =         15
    
                                                    F(1,55)           =       5.43
    corr(u_i, Xb)  = -0.1406                        Prob > F          =     0.0234
    
    ------------------------------------------------------------------------------
         ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |   .0151366   .0064937     2.33   0.023     .0021228    .0281503
           _cons |   1.374028   .1936272     7.10   0.000     .9859904    1.762066
    -------------+----------------------------------------------------------------
         sigma_u |  .20406388
         sigma_e |  .30293713
             rho |  .31212907   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(4, 55) = 5.88                       Prob > F = 0.0005
    
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I doubt that you will learn anything from looking at 11,000 coefficients, but you will have to judge how useful that approach really is. Anyway, when you type

      Code:
      reg y x i.product_code
      Stata will omit one of the product_code indicator variables (typically the first) because it is collinear with the constant term. Hence, the coefficients from your first model represent the difference to the omitted product_code. To replicate these coefficients you want

      Code:
      xtreg y x i.product_code
      predict u , u
      sort product_code
      replace u = u-u[1] if (_n < 1)
      I do not know what you mean by "true" coefficients but when you are referring to coefficients that are not relative to the omitted reference, then you are already looking at what you want.

      Following up on Carlo's suggestion, I believe that

      Code:
      areg ...
      predict d , d
      will give you the same results that you get after regress, when you include the indicators, manually.

      Best
      Daniel
      Last edited by daniel klein; 09 Jul 2018, 09:39.

      Comment


      • #4
        Actually my coefficients of interests are ones that are on the product code. Let me make it more explicit:

        Code:
              Source |       SS           df       MS      Number of obs   =        78
        -------------+----------------------------------   F(31, 47)       =     21.33
               Model |  95.8415874        31  3.09166411   Prob > F        =    0.0000
            Residual |  6.81388421        47   .14497626   R-squared       =    0.9336
        -------------+----------------------------------   Adj R-squared   =    0.8898
               Total |  102.655472        78  1.31609579   Root MSE        =    .38076
        
        ------------------------------------------------------------------------------
                   y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                   x |   .0794534   .0582508     1.36   0.179    -.0377321    .1966389
                     |
        product_code |
           11000040  |   .7680966   .3064657     2.51   0.016     .1515671    1.384626
           11000098  |   .9083795   .2845688     3.19   0.003     .3359008    1.480858
           11000133  |   .8863397   .3341671     2.65   0.011     .2140823    1.558597
           11000138  |   .5385099   .3756782     1.43   0.158    -.2172571    1.294277
           11000171  |   .4858168   .4035712     1.20   0.235    -.3260637    1.297697
           11000174  |   1.037059   .3256593     3.18   0.003     .3819173    1.692201
           11000232  |   .5927253   .3491215     1.70   0.096    -.1096166    1.295067
           11000260  |   .5511151   .3692924     1.49   0.142    -.1918053    1.294036
           11000289  |   .6951976   .3458356     2.01   0.050    -.0005339    1.390929
           11000332  |   .8943599   .3709671     2.41   0.020     .1480703    1.640649
           11000357  |   .5956999   .3477373     1.71   0.093    -.1038572    1.295257
           11000424  |   .9345632    .351342     2.66   0.011     .2277543    1.641372
           11000474  |   1.016387   .3369966     3.02   0.004      .338437    1.694336
           11000514  |   .9097961   .2837978     3.21   0.002     .3388686    1.480724
           11000583  |   .8566272   .3905143     2.19   0.033     .0710138    1.642241
           11000640  |   .5362127   .3768546     1.42   0.161     -.221921    1.294346
           11000654  |   .9761923   .3862906     2.53   0.015     .1990758    1.753309
           11000786  |   .5888021   .3509596     1.68   0.100    -.1172377    1.294842
           11000850  |   .7574469   .3119561     2.43   0.019     .1298723    1.385022
           11000936  |   .9218053   .3025017     3.05   0.004     .3132505     1.53036
           11000944  |   .5815607   .3543886     1.64   0.107    -.1313772    1.294499
           11000952  |   .7414235   .3203981     2.31   0.025     .0968656    1.385981
           11000968  |   .5705761   .3596773     1.59   0.119    -.1530013    1.294154
           11000988  |   .8894636   .2950223     3.01   0.004     .2959554    1.482972
           11001038  |   .5914404    .349722     1.69   0.097    -.1121096     1.29499
           11001057  |   1.029517   .3297602     3.12   0.003      .366125    1.692909
           11001060  |   .4931866   .3995625     1.23   0.223    -.3106295    1.297003
           11001109  |   .7956432   .3232787     2.46   0.018     .1452903    1.445996
           11001124  |   .9478137    .345181     2.75   0.009     .2533992    1.642228
           11001179  |   .6126812   .3399947     1.80   0.078       -.0713    1.296662
        ------------------------------------------------------------------------------
        I want to obtain same coefficients on the product codes from xtreg or another alternative

        Comment


        • #5
          I think I got it, thank you very much!

          Comment


          • #6
            Erdem:
            elaborating on previous replies to your original post, you may probably try yourself and compare what -xtreg,fe- and -areg- give you back.
            This is the only practical advice that springs to my mind, as no interested listers can challenge with this stuff without a -dataex- example/excerpt.

            PS: Crossed with Erdem's reply, who refer he've made it. I would encourage Erdam to post his fix, as other listers may benefit from it.
            Last edited by Carlo Lazzaro; 09 Jul 2018, 09:59.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Dear Carlo,
              Actually I was referring o coefficients that are not relative to the omitted reference, and based on Daniel's explanation,

              Code:
               
               areg ... predict d , d
              was what I wanted.

              Comment


              • #8
                Erdem:
                sorry for mispelling your name in my previous reply and thanks for sharing what you did.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment

                Working...
                X