Announcement

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

  • Difference between reg and xtreg

    Hello everybody

    What is exactly the difference between those two commands?

    Thank you in advance

  • #2
    reg Y X= OLS regression using cross sectional data
    xtreg Y X, fe=fixed effects within estimation using panel data (cross sectional data observed over a period of time, so the data structure has added time dimension)

    Comment


    • #3
      Thank you for the answer. But how can I add the column of years (period of time), because after regressing it shows Group variable: firmcode , but in fact I need to add the variable Year and not the variable firmcode

      Comment


      • #4
        Command: xtset firmcode Year (if your variable names are like this, frim 1 firm 2 firm 3 ... firm N, collected over Year 1, Year 2, ... Year N).

        Alternatively: click on Statistics--Longitudinal/Panel data--Setup and utilities--Declare dataset to be panel data

        Comment


        • #5
          xtset firmcode Year
          No, that will not do it.

          -xtset- will cause -xtreg, fe- (or -xtreg, re-) to recognize the firmcode variable as the fixed (or random) effect level. But it does not cause -xtreg, fe- to incorporate Year. To do that, you must explicitly include Year in the regression:
          Code:
          xtset firmcode Year
          xtreg dep_var indep_vars covariates i.Year, fe
          The only thing that include Year in the -xtset- command does is enable Stata to identify the time variable for purposes of calculating leads, lags, and differences, and to structure autoregressive correlation. If you're not using any of those things, there is no need to mention Year in -xtset-. But you do need to include i.Year in the -xtreg- variable list if you want Year to be included.

          Comment


          • #6
            Dr Schechter thank you again !

            Comment


            • #7
              Theofanis:
              your question might be due to the fact that you can run fixed effect estimator using -regress- too (but -xtreg,fe- outperforms -regress- in this respect).
              As you can see from the following toy-example, set aside the constant and panel-specific statistics, coefficients and standard errors are the same:
              Code:
              . . use "https://www.stata-press.com/data/r17/nlswork.dta"
              (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
              
              . regress ln_wage age i.idcode i.year if idcode<=3
              
                    Source |       SS           df       MS      Number of obs   =        39
              -------------+----------------------------------   F(17, 21)       =      2.68
                     Model |  3.54194923        17  .208349955   Prob > F        =    0.0171
                  Residual |  1.63378973        21  .077799511   R-squared       =    0.6843
              -------------+----------------------------------   Adj R-squared   =    0.4288
                     Total |  5.17573896        38  .136203657   Root MSE        =    .27893
              
              ------------------------------------------------------------------------------
                   ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       age |   .3010572   .3561559     0.85   0.407    -.4396095    1.041724
                           |
                    idcode |
                        2  |  -.3898423     .11632    -3.35   0.003     -.631743   -.1479415
                        3  |  -2.247118   2.111457    -1.06   0.299    -6.638133    2.143897
                           |
                      year |
                       69  |  -.0920902   .5314565    -0.17   0.864    -1.197315    1.013134
                       70  |  -.8648493    .779214    -1.11   0.280    -2.485314    .7556149
                       71  |  -1.248506    1.09967    -1.14   0.269    -3.535396    1.038383
                       72  |   -1.39387   1.443494    -0.97   0.345    -4.395779     1.60804
                       73  |  -1.520276    1.79214    -0.85   0.406    -5.247236    2.206684
                       75  |  -2.049717   2.495803    -0.82   0.421    -7.240024     3.14059
                       77  |  -2.657565   3.203292    -0.83   0.416    -9.319175    4.004045
                       78  |  -2.751196   3.557758    -0.77   0.448    -10.14996    4.647567
                       80  |  -3.324016   4.267534    -0.78   0.445    -12.19884    5.550808
                       82  |  -4.027975   4.983977    -0.81   0.428    -14.39272    6.336774
                       83  |  -4.207353   5.333467    -0.79   0.439     -15.2989    6.884199
                       85  |  -4.730657   6.044586    -0.78   0.443    -17.30106    7.839747
                       87  |  -5.407995   6.755956    -0.80   0.432    -19.45777    8.641785
                       88  |  -5.901929   7.348904    -0.80   0.431    -21.18481    9.380954
                           |
                     _cons |  -2.882579   5.734884    -0.50   0.620    -14.80892    9.043766
              ------------------------------------------------------------------------------
              
              . xtreg ln_wage age i.year if idcode<=3, fe
              
              Fixed-effects (within) regression               Number of obs     =         39
              Group variable: idcode                          Number of groups  =          3
              
              R-squared:                                      Obs per group:
                   Within  = 0.5596                                         min =         12
                   Between = 0.4744                                         avg =       13.0
                   Overall = 0.0413                                         max =         15
              
                                                              F(15,21)          =       1.78
              corr(u_i, Xb) = -0.9573                         Prob > F          =     0.1102
              
              ------------------------------------------------------------------------------
                   ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                       age |   .3010572   .3561559     0.85   0.407    -.4396095    1.041724
                           |
                      year |
                       69  |  -.0920902   .5314565    -0.17   0.864    -1.197315    1.013134
                       70  |  -.8648493    .779214    -1.11   0.280    -2.485314    .7556149
                       71  |  -1.248506    1.09967    -1.14   0.269    -3.535396    1.038383
                       72  |   -1.39387   1.443494    -0.97   0.345    -4.395779     1.60804
                       73  |  -1.520276    1.79214    -0.85   0.406    -5.247236    2.206684
                       75  |  -2.049717   2.495803    -0.82   0.421    -7.240024     3.14059
                       77  |  -2.657565   3.203292    -0.83   0.416    -9.319175    4.004045
                       78  |  -2.751196   3.557758    -0.77   0.448    -10.14996    4.647567
                       80  |  -3.324016   4.267534    -0.78   0.445    -12.19884    5.550808
                       82  |  -4.027975   4.983977    -0.81   0.428    -14.39272    6.336774
                       83  |  -4.207353   5.333467    -0.79   0.439     -15.2989    6.884199
                       85  |  -4.730657   6.044586    -0.78   0.443    -17.30106    7.839747
                       87  |  -5.407995   6.755956    -0.80   0.432    -19.45777    8.641785
                       88  |  -5.901929   7.348904    -0.80   0.431    -21.18481    9.380954
                           |
                     _cons |  -3.866807   6.544144    -0.59   0.561     -17.4761    9.742485
              -------------+----------------------------------------------------------------
                   sigma_u |  1.2007631
                   sigma_e |  .27892564
                       rho |   .9488037   (fraction of variance due to u_i)
              ------------------------------------------------------------------------------
              F test that all u_i=0: F(2, 21) = 6.09                       Prob > F = 0.0082
              
              . 
              
              .
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Thanks Carlo, I really appreciate your help

                Comment

                Working...
                X