Announcement

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

  • Time and country random effects

    Hello everyone!

    I am working with panel data consisting of 9 countries over the period of 2000-2017. I want to use country, time and both country and time random effects in my model but a little bit confused with commands. My panel setting is "xtset country_id year".

    For time random effects, is the command the same as for time fixed effects, when you only need command "reg y x i.year"?

    Does command for country random effects looks like "xtreg y x i.country_id, re" and for both country and time random effects "xtreg y x i.country_id i.year, re"?

    Thank you for your help, Sergey Medvedev

  • #2
    For country random effects
    Code:
    xtreg y x, re
    For country random effects with time fixed effects
    Code:
    xtreg y x i.year, re
    The general principle with data that has been -xtset panelvar timevar- is that -xtreg- will create the fixed or random effect of the panelvar for you, but that to get a time fixed effect you have to specify it as i.year in the -xtreg- varlist. And the i. notation is never used to create random effects--only fixed effects.

    You cannot do both country and time random effects with -xtreg-. That requires using -mixed-

    Code:
    mixed y x || _all: R.country_id || time:
    (As this is panel data, I assume that country_id and time are crossed.)

    Comment


    • #3
      Thank you, Clyde, for quick response

      I have put all my variables into log form.

      When I use command "xtreg logy logx, re" for country random effects, I receive absolutely same results for coefficients and standard errors as when I use command "reg logy logx". Same is happening when I am using commands "reg logy logx i.year" and "xtreg logy logx i.year, re". Is this because of the logs or I doing something wrong?

      Comment


      • #4
        You need to show example data (use the -dataex- command) and the actual outputs you are getting from Stata (use code delimiters) in order to get answers to these questions.

        If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

        Comment


        • #5
          Thank you, Clyde, for help. Here I show you country random effects

          Code:
           xtreg logy logx, re
          
          Random-effects GLS regression                   Number of obs     =        139
          Group variable: country_id                      Number of groups  =          9
          
          R-sq:                                           Obs per group:
               within  = 0.0013                                         min =         11
               between = 0.3274                                         avg =       15.4
               overall = 0.0120                                         max =         18
          
                                                          Wald chi2(1)      =       1.66
          corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.1975
          
          ------------------------------------------------------------------------------
                  logy |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  logx |    .051001   .0395763     1.29   0.198    -.0265672    .1285692
                 _cons |   1.636017   .0908809    18.00   0.000     1.457894    1.814141
          -------------+----------------------------------------------------------------
               sigma_u |          0
               sigma_e |  .92124328
                   rho |          0   (fraction of variance due to u_i)
          ------------------------------------------------------------------------------
          Here is a simple regression which has identical coefficients and standard errors to country random effects

          Code:
          reg logy logx
          
                Source |       SS           df       MS      Number of obs   =       139
          -------------+----------------------------------   F(1, 137)       =      1.66
                 Model |  1.38222205         1  1.38222205   Prob > F        =    0.1997
              Residual |  114.028083       137  .832321775   R-squared       =    0.0120
          -------------+----------------------------------   Adj R-squared   =    0.0048
                 Total |  115.410305       138  .836306559   Root MSE        =    .91232
          
          ------------------------------------------------------------------------------
                  logy |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  logx |    .051001   .0395763     1.29   0.200    -.0272585    .1292605
                 _cons |   1.636017   .0908809    18.00   0.000     1.456307    1.815728
          ------------------------------------------------------------------------------




          Same is happening when I do regression with country random effects with time fixed effects

          Code:
           xtreg logy logx i.year, re
          
          Random-effects GLS regression                   Number of obs     =        139
          Group variable: country_id                      Number of groups  =          9
          
          R-sq:                                           Obs per group:
               within  = 0.3466                                         min =         11
               between = 0.0017                                         avg =       15.4
               overall = 0.3085                                         max =         18
          
                                                          Wald chi2(18)     =      53.54
          corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
          
          ------------------------------------------------------------------------------
                  logy |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  logx |   .0813375   .0363366     2.24   0.025     .0101191    .1525559
                       |
                  year |
                 2001  |   .1056297   .4359558     0.24   0.809     -.748828    .9600874
                 2002  |   .2082459   .4367029     0.48   0.633    -.6476761    1.064168
                 2003  |   .2682679   .4229652     0.63   0.526    -.5607287    1.097265
                 2004  |   .2667727   .4237796     0.63   0.529    -.5638201    1.097365
                 2005  |   .3771766   .4374389     0.86   0.389    -.4801879    1.234541
                 2006  |   .2124358   .4137042     0.51   0.608    -.5984096    1.023281
                 2007  |   .2473964   .4140726     0.60   0.550    -.5641711    1.058964
                 2008  |   .0251364   .4141938     0.06   0.952    -.7866685    .8369412
                 2009  |  -1.063661   .4558732    -2.33   0.020    -1.957156   -.1701659
                 2010  |  -.2111883   .4242196    -0.50   0.619    -1.042643    .6202669
                 2011  |   -.633844   .4141719    -1.53   0.126    -1.445606     .177918
                 2012  |  -.4587566   .4371459    -1.05   0.294    -1.315547    .3980336
                 2013  |  -.4103464   .4143602    -0.99   0.322    -1.222478    .4017848
                 2014  |  -.7944239   .4142851    -1.92   0.055    -1.606408    .0175601
                 2015  |  -.8628972   .4569894    -1.89   0.059     -1.75858    .0327855
                 2016  |  -1.103365    .459163    -2.40   0.016    -2.003308   -.2034218
                 2017  |  -1.033715   .4254235    -2.43   0.015     -1.86753   -.1999004
                       |
                 _cons |   1.847076   .3082327     5.99   0.000     1.242951    2.451201
          -------------+----------------------------------------------------------------
               sigma_u |          0
               sigma_e |  .79666179
                   rho |          0   (fraction of variance due to u_i)
          ------------------------------------------------------------------------------
          Which is identical to simple regression with time effect

          Code:
          reg logy logx i.year
          
                Source |       SS           df       MS      Number of obs   =       139
          -------------+----------------------------------   F(18, 120)      =      2.97
                 Model |  35.6076426        18  1.97820236   Prob > F        =    0.0002
              Residual |  79.8026627       120  .665022189   R-squared       =    0.3085
          -------------+----------------------------------   Adj R-squared   =    0.2048
                 Total |  115.410305       138  .836306559   Root MSE        =    .81549
          
          ------------------------------------------------------------------------------
                  logy |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                  logx |   .0813375   .0363366     2.24   0.027     .0093936    .1532814
                       |
                  year |
                 2001  |   .1056297   .4359558     0.24   0.809    -.7575325    .9687919
                 2002  |   .2082459   .4367029     0.48   0.634    -.6563955    1.072887
                 2003  |   .2682679   .4229652     0.63   0.527    -.5691738     1.10571
                 2004  |   .2667727   .4237796     0.63   0.530    -.5722815    1.105827
                 2005  |   .3771766   .4374389     0.86   0.390     -.488922    1.243275
                 2006  |   .2124358   .4137042     0.51   0.609    -.6066698    1.031541
                 2007  |   .2473964   .4140726     0.60   0.551    -.5724386    1.067231
                 2008  |   .0251364   .4141938     0.06   0.952    -.7949384    .8452112
                 2009  |  -1.063661   .4558732    -2.33   0.021    -1.966258   -.1610638
                 2010  |  -.2111883   .4242196    -0.50   0.620    -1.051114     .628737
                 2011  |   -.633844   .4141719    -1.53   0.129    -1.453875    .1861875
                 2012  |  -.4587566   .4371459    -1.05   0.296    -1.324275    .4067618
                 2013  |  -.4103464   .4143602    -0.99   0.324    -1.230751     .410058
                 2014  |  -.7944239   .4142851    -1.92   0.058     -1.61468    .0258319
                 2015  |  -.8628972   .4569894    -1.89   0.061    -1.767704    .0419099
                 2016  |  -1.103365    .459163    -2.40   0.018    -2.012476   -.1942539
                 2017  |  -1.033715   .4254235    -2.43   0.017    -1.876024   -.1914062
                       |
                 _cons |   1.847076   .3082327     5.99   0.000     1.236797    2.457356
          ------------------------------------------------------------------------------
          I am confused, why this is happening

          Comment


          • #6
            So, the explanation is in the bottom part of the output from the -xtreg, re- commands: sigma_u is coming out 0, which means that there is no variation at the country level. That is, there is no systematic country-to-country variation in y (or log y): the expected value of y (log y), given x (log x) and year is the same regardless of the country. When that is true, then random effects regression is identical to ordinary linear regression.

            If that isn't supposed to be true in your situation, then something is wrong with your data. It is unlikely to have anything to do with taking logarithms, unless the variables x and y have some 0 or negative values that are leading to omission of those observations in the data and those particular observations are the only ones where country-level effects are operating.

            Comment


            • #7
              This was extremely helpful, Clyde, thank you very much!

              So in my data, as there is no systematic country-to-country variation in y, there is no point of using country random effects and regressions using country random effects and time fixed effects, as they are identical to ordinary linear regression. However, when I compute similar regressions with fixed effects, my sigma_u is coming to be bigger than 0. Does it mean that instead of using random effects it is more beneficial to use fixed effects?

              Comment


              • #8
                One last question. As in my case, random effects regression is identical to ordinary linear regression, if I want to include both time and country effects in my regression but due to them being identical to ordinary linear regression, can command "reg logy logx i.country_id i.year" be valid ?

                Comment


                • #9
                  Sergey:
                  in your #7 you do not say if under -fe- the F-test appearing as a footnote of -xtreg,fe- oucome table reaches statistical significance.
                  Moreover, you should have tested random effects via -xttest0- and -fe- vs -re- specification via -hausman- test (but, as per your results, I guess that your dataset can be better analyzed with a pooled OLS).
                  Eventually (concerning your #8), if you go pooled OLS, you should consider -cluster-ing your standard errors (even though they are only 9 as per your post), since the panel structure of your dataset implies that the observations are not independent: the ones belonging to the same group (ie, panel) are more similar than the ones belonging to another group.
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    I did use hausman test in order to determine whether to use random effects or fixed effects. My p-value was big, implying that I cannot reject H0 and should use random effects. However, as Clyde stated above, my random effects regression are identical to ordinary linear regression so I should consider using pooled OLS.

                    Can I therefore, in order to use time, country and time and country effects in my regression use "i.year" "i.country_id" without using "xtreg" or there is another way of including them?

                    Is it correct to use such command?
                    Code:
                    reg logy logx i.country_id i.year
                    When you say that I should consider -cluster-ing my standard errors, do you mean that I should use "vce(robust)" command?

                    Thank you in advance for your help!
                    Last edited by Sergey Medvedev; 08 Feb 2019, 07:34.

                    Comment


                    • #11
                      Sergey:
                      I meant
                      Code:
                      reg logy logx i.country_id i.year, vce(cluster id)
                      Kind regards,
                      Carlo
                      (Stata 19.0)

                      Comment


                      • #12
                        Thank you very much for your help, Carlo!

                        Comment

                        Working...
                        X