Announcement

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

  • Time FEs with xtregar

    Hello! Can anyone explain why xtregar will not allow the inclusion of the time variable (as fixed effect, with i.year, for example) in the varlist? The "time variable" is the one I used in xtset.
    Is there a standard workaround? Thank you!

  • #2
    Ha?

    Code:
    webuse grunfeld, clear
    xtset company year
    xtregar invest mvalue kstock i.year, fe
    Res.:

    Code:
    .         . xtregar invest mvalue kstock i.year, fe
    
    FE (within) regression with AR(1) disturbances  Number of obs     =        190
    Group variable: company                         Number of groups  =         10
    
    R-squared:                                      Obs per group:
         Within  = 0.6513                                         min =         19
         Between = 0.7838                                         avg =       19.0
         Overall = 0.7798                                         max =         19
    
                                                    F(20,160)         =      14.94
    corr(u_i, Xb) = -0.1416                         Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          mvalue |   .0938865   .0104378     8.99   0.000     .0732729    .1145001
          kstock |   .4076907   .0373936    10.90   0.000      .333842    .4815393
                 |
            year |
           1936  |   22.60707   15.23516     1.48   0.140    -7.480873    52.69502
           1937  |   29.02835   20.63253     1.41   0.161    -11.71886    69.77557
           1938  |   32.19837   23.69301     1.36   0.176    -14.59298    78.98973
           1939  |   17.30833   25.51947     0.68   0.499    -33.09011    67.70676
           1940  |   50.88403   27.01934     1.88   0.061    -2.476513    104.2446
           1941  |   79.24101   27.76837     2.85   0.005     24.40121    134.0808
           1942  |   73.97942   28.25514     2.62   0.010      18.1783    129.7805
           1943  |   56.66199   28.31439     2.00   0.047     .7438482    112.5801
           1944  |   58.95475   28.56968     2.06   0.041     2.532449     115.377
           1945  |   49.74642   28.40551     1.75   0.082    -6.351667    105.8445
           1946  |   75.78518   28.05301     2.70   0.008     20.38324    131.1871
           1947  |   57.76681   26.94116     2.14   0.034     4.560676    110.9729
           1948  |   51.01013   26.04522     1.96   0.052    -.4266119    102.4469
           1949  |   20.19058   24.97134     0.81   0.420    -29.12536    69.50651
           1950  |   18.35979   23.75434     0.77   0.441     -28.5527    65.27228
           1951  |   36.28607   21.77871     1.67   0.098    -6.724731    79.29688
           1952  |   32.36863   18.82811     1.72   0.088    -4.815034    69.55229
           1953  |   30.71474   14.03026     2.19   0.030     3.006356    58.42313
           1954  |          0  (omitted)
                 |
           _cons |  -124.2761   10.59512   -11.73   0.000    -145.2004   -103.3518
    -------------+----------------------------------------------------------------
          rho_ar |  .68127018
         sigma_u |  96.029876
         sigma_e |  39.732352
         rho_fov |  .85383317   (fraction of variance because of u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(9,160) = 12.27                      Prob > F = 0.0000
    
    .

    Comment


    • #3
      Originally posted by Gabriel Mihalache View Post
      The "time variable" is the one I used in xtset.
      OK, did you do this?

      Code:
      xtset year
      and then

      Code:
      xtregar ... i.year, fe
      In this case, the year fixed effects are already included by xtset, so i.year would be collinear with the time effects and should not be added again.

      Comment


      • #4
        Thank you for your reply! Using your example, I get this error:


        Code:
        . webuse grunfeld, clear
        
        . xtset company year
        
        Panel variable: company (strongly balanced)
         Time variable: year, 1935 to 1954
                 Delta: 1 year
        
        . xtregar invest mvalue kstock i.year, fe
        time variable may not be included in varlist
        r(198);

        Comment


        • #5
          I should have indicated that my version of Stata is StataNow 18.5. Is your version Stata 19/ StataNow 19.5? There may be some statistical reason for not doing this (i.e., applying the AR(1) correction after the time dummies are partialled out), but it is not discussed in the xtregar manual (https://www.stata.com/manuals/xtxtregar.pdf). There should be a way to force Stata to do this—either by using version control or by cloning the time variable. However, what you should be more concerned about are the statistical properties of such a procedure. Perhaps if you write to Technical Services, an expert can provide the underlying reasoning.


          Code:
          webuse grunfeld, clear
          xtset company year
          version 18: xtregar invest mvalue kstock i.year, fe
          or

          Code:
          webuse grunfeld, clear
          xtset company year
          clonevar time = year
          xtregar invest mvalue kstock i.time, fe

          Comment


          • #6
            I am getting the same error in Stata 18. Probably Andrew has a newer version of Stata, and apparently up to Stata 18 the factor variable notation has not been implemented in -xtregar-.

            Just generate the dummies manually, like this:

            Code:
            . . webuse grunfeld, clear
            
            . 
            . 
            . 
            . . xtset company year
            
            Panel variable: company (strongly balanced)
             Time variable: year, 1935 to 1954
                     Delta: 1 year
            
            . xtregar invest mvalue kstock i.year, fe
            time variable may not be included in varlist
            r(198);
            
            . tab year, gen(yr)
            
                   Year |      Freq.     Percent        Cum.
            ------------+-----------------------------------
                   1935 |         10        5.00        5.00
                   1936 |         10        5.00       10.00
                   1937 |         10        5.00       15.00
                   1938 |         10        5.00       20.00
                   1939 |         10        5.00       25.00
                   1940 |         10        5.00       30.00
                   1941 |         10        5.00       35.00
                   1942 |         10        5.00       40.00
                   1943 |         10        5.00       45.00
                   1944 |         10        5.00       50.00
                   1945 |         10        5.00       55.00
                   1946 |         10        5.00       60.00
                   1947 |         10        5.00       65.00
                   1948 |         10        5.00       70.00
                   1949 |         10        5.00       75.00
                   1950 |         10        5.00       80.00
                   1951 |         10        5.00       85.00
                   1952 |         10        5.00       90.00
                   1953 |         10        5.00       95.00
                   1954 |         10        5.00      100.00
            ------------+-----------------------------------
                  Total |        200      100.00
            
            . xtregar invest mvalue kstock yr*, fe
            note: yr20 omitted because of collinearity.
            
            FE (within) regression with AR(1) disturbances  Number of obs     =        190
            Group variable: company                         Number of groups  =         10
            
            R-squared:                                      Obs per group:
                 Within  = 0.6513                                         min =         19
                 Between = 0.7838                                         avg =       19.0
                 Overall = 0.0180                                         max =         19
            
                                                            F(20,160)         =      14.94
            corr(u_i, Xb) = -0.0017                         Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                  invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                  mvalue |   .0938865   .0104378     8.99   0.000     .0732729    .1145001
                  kstock |   .4076907   .0373936    10.90   0.000      .333842    .4815393
                     yr1 |  -96356.17   44014.77    -2.19   0.030      -183281   -9431.333
                     yr2 |  -65601.06   29972.83    -2.19   0.030    -124794.4   -6407.667
                     yr3 |  -44657.49   20406.63    -2.19   0.030    -84958.58   -4356.399
                     yr4 |  -30390.47   13889.82    -2.19   0.030    -57821.49   -2959.451
                     yr5 |  -20687.82   9449.858    -2.19   0.030    -39350.36   -2025.284
                     yr6 |  -14033.98   6425.021    -2.18   0.030    -26722.76   -1345.196
                     yr7 |  -9495.432   4364.444    -2.18   0.031    -18114.78   -876.0849
                     yr8 |  -6428.035   2960.811    -2.17   0.031    -12275.34   -580.7253
                     yr9 |  -4352.041   2004.415    -2.17   0.031    -8310.563   -393.5196
                    yr10 |  -2923.638   1352.812    -2.16   0.032    -5595.309   -251.9674
                    yr11 |   -1961.28    908.943    -2.16   0.032    -3756.353   -166.2073
                    yr12 |  -1273.342   606.6414    -2.10   0.037    -2471.399   -75.28522
                    yr13 |  -840.4285    401.292    -2.09   0.038    -1632.941   -47.91619
                    yr14 |  -539.9785   261.2814    -2.07   0.040    -1055.983    -23.9735
                    yr15 |  -361.5073   165.9385    -2.18   0.031    -689.2194   -33.79517
                    yr16 |  -220.7546   100.9425    -2.19   0.030     -420.106   -21.40312
                    yr17 |  -105.6904   56.52777    -1.87   0.063    -217.3272    5.946425
                    yr18 |  -43.43064   26.28637    -1.65   0.100    -95.34365    8.482359
                    yr19 |          0  (omitted)
                    yr20 |          0  (omitted)
                   _cons |  -189.9274   16.52428   -11.49   0.000    -222.5612   -157.2936
            -------------+----------------------------------------------------------------
                  rho_ar |  .68127018
                 sigma_u |  96.029876
                 sigma_e |  39.732352
                 rho_fov |  .85383317   (fraction of variance because of u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(9,160) = 12.27                      Prob > F = 0.0000
            
            .

            Comment


            • #7
              Originally posted by Joro Kolev View Post
              I am getting the same error in Stata 18. Probably Andrew has a newer version of Stata, and apparently up to Stata 18 the factor variable notation has not been implemented in -xtregar-.

              Just generate the dummies manually, like this:
              Thanks for testing this, the issue must have been with older versions of Stata then. Does cloning the time variable like in #5 work for you?

              Comment


              • #8
                Great! Thank you Joro and Andrew for your help. This will be fine. Greatly appreciated!

                Comment

                Working...
                X