Announcement

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

  • Test for heteroskedasticity in model with random effects

    Hello everyone,

    I am using an unbalanced panel dataset and want to use -xtreg-.
    Actually I am a bit confused regarding testing my model.
    I started with PB-LM test and F-test to find random and fixed effects and found both.
    Afterwards I run a Hausman test which recommanded me to use re model.
    Furthermore I ran a test for autocorrlation which was significant and therefore I idenfitied autocorrelation.

    Now i want to do a test for heteroskedasticity. I know that for a fixed effects model I can use the -xttest3- command. But since I identified random effects are appropriate I need to run a different test.
    In my research I found that I may have to switch to -xtgls- and use the -xttest2- to identify weather there is heteroskedasticity or not, but I get an error:

    Code:
    Code:
    local controls "fs lev itq rdi growth cap_exp"
    xtgls tq cvc1 `controls'
    estimates store RE
    xttest2
    Error:
    Code:
    .         local controls "fs lev itq rdi growth cap_exp"
    
    .         xtgls tq cvc1 `controls'
    
    Cross-sectional time-series FGLS regression
    
    Coefficients:  generalized least squares
    Panels:        homoskedastic
    Correlation:   no autocorrelation
    
    Estimated covariances      =         1          Number of obs     =        182
    Estimated autocorrelations =         0          Number of groups  =         17
    Estimated coefficients     =         8          Obs per group:
                                                                  min =          8
                                                                  avg =   10.70588
                                                                  max =         11
                                                    Wald chi2(7)      =     934.72
    Log likelihood             = -127.4512          Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
              tq | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
            cvc1 |  -.0019507   .0010543    -1.85   0.064     -.004017    .0001157
              fs |  -.1371241   .0409864    -3.35   0.001    -.2174559   -.0567922
             lev |    .067518   .0457678     1.48   0.140    -.0221852    .1572211
             itq |   1.038877   .0551196    18.85   0.000     .9308442    1.146909
             rdi |   2.562943   .9972166     2.57   0.010     .6084342    4.517451
          growth |   .0984387   .1628702     0.60   0.546     -.220781    .4176585
         cap_exp |   3.262956   1.287108     2.54   0.011     .7402705    5.785642
           _cons |   1.158686   .4346392     2.67   0.008     .3068091    2.010563
    ------------------------------------------------------------------------------
    
    .         estimates store RE
    
    .         xttest2
    
    Correlation matrix of residuals is singular.
    not possible with test

    Is there anything wrong in my command or is it still the worng command to use?
    Or do I still have to stick to -xtreg- and the fe model, since after running a Sargan Hansen test (-xtoverid-) it recommends me to go with the fe model. So do I have to do the test for heteroskedasticity after my Sargan Hansen test? Actually I think I have to do it before.


    Hopefully you can help me I got a bit confused with all these tests.


    Best regards

    Jana






  • #2
    Jana:
    Furthermore I ran a test for autocorrlation which was significant and therefore I idenfitied autocorrelation.
    Your statement is enough to go -xtreg,re robust- or, in the very same fashion, -xtreg,re vce(cluster clusterid)- as both these options take care of heteroskedasticity and/or autocorrelation.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Carlo:
      thanks for your fast answer. I am thinking in the same way.

      But for my thesis it is needed that I show how I tested for heteroskedasticity.
      Do you have an advice for me how to do it?

      Best regards

      Jana

      Comment


      • #4
        Jana:
        you can use visual inspection, as in the following toy-example (in which -e- distribution is heteroskedstic):
        Code:
        use "https://www.stata-press.com/data/r16/nlswork.dta"
        
        . xtreg ln_wage c.age##c.age, re
        
        Random-effects GLS regression                   Number of obs     =     28,510
        Group variable: idcode                          Number of groups  =      4,710
        
        R-sq:                                           Obs per group:
             within  = 0.1087                                         min =          1
             between = 0.1015                                         avg =        6.1
             overall = 0.0870                                         max =         15
        
                                                        Wald chi2(2)      =    3388.51
        corr(u_i, X)   = 0 (assumed)                    Prob > chi2       =     0.0000
        
        ------------------------------------------------------------------------------
             ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
                 age |   .0590339   .0027172    21.73   0.000     .0537083    .0643596
                     |
         c.age#c.age |  -.0006758   .0000451   -15.00   0.000    -.0007641   -.0005876
                     |
               _cons |   .5479714   .0397476    13.79   0.000     .4700675    .6258752
        -------------+----------------------------------------------------------------
             sigma_u |   .3654049
             sigma_e |  .30245467
                 rho |  .59342665   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        
        . predict res, e
        
        . predict fitted, xb
        
        . twoway (scatter res fitted)
        
        .
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Thank you Carlo!

          Am I correct to interpret this output as having heteroskedasticity because of the clustering at 0 and the cone shape?

          Thank you for all the help!

          Kind regards,
          Jana
          Attached Files

          Comment


          • #6
            Jana:
            yes, you are.
            But are you sure that you've plotted the entire residual distribution vs. fitted values?
            Last edited by Carlo Lazzaro; 07 Dec 2021, 23:57.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Carlo:
              thanks for confirmation!

              I think so. I followed your instructions.

              Code:
              Code:
              local controls "fs lev itq rdi growth cap_exp"
                  xtreg tq cvc `controls' i.fyear, re 
                  predict res, e
                  predict fitted, xb
                  twoway (scatter res fitted)

              Thanks for all your help.

              Best regards
              Jana

              Comment


              • #8
                Jana:
                another more substantive issue rests on the correct specification of your model, as a misspecified model can cause heteroskedastciity among other nuisances.
                If you're 100% sure that your model is not misspecified, go -xtreg,re- with non-default standard errors as per #2. This way you will manage both heteroskedasticity and autocorrelation.
                Eventually, you can test the joint significance of -i.fyear- via -testparm-.
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment


                • #9
                  Originally posted by Carlo Lazzaro View Post
                  Jana:
                  another more substantive issue rests on the correct specification of your model, as a misspecified model can cause heteroskedastciity among other nuisances.
                  If you're 100% sure that your model is not misspecified, go -xtreg,re- with non-default standard errors as per #2. This way you will manage both heteroskedasticity and autocorrelation.
                  Eventually, you can test the joint significance of -i.fyear- via -testparm-.

                  Hello Mr. Lazzaro,

                  I have a solution as I am in the same situation, what if :

                  As we know that the classic Breusch-Pagan will not be directly applicable to panel data, we could still apply it by extracting the residuals of the random effect model, applying a regression using the residuals as dependant variable and we will be able to detect heteroscedasticity ?

                  Comment


                  • #10
                    Remy:
                    welcome to this forum.
                    See stata - Testing for heteroskedasticity in panel data vs time series? - Economics Stack Exchange
                    Kind regards,
                    Carlo
                    (Stata 19.0)

                    Comment

                    Working...
                    X