Announcement

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

  • WLS in data panel

    Hello, does anyone know a Stata comman to run a Weighted Least Squares estimation in a panel model with both time and individuals fixed effects?

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex.

    xtreg provides for weights. xtgls also might be what you want.

    Comment


    • #3
      It depends what you're weighting for. Heteroskedasticity? Survey design? Attrition? Treatment effect estimation?

      Comment


      • #4
        Jeff Wooldridge I am trying to weight for variance in but I am unable to put the 'sd' variable or 'variance' variable in the weight. I saw one example where the variance weighted least squares regression is done by using the code: regress y x [aweight=s^(-2)]...where s is the SD but in my stata doesn't read the SD or variance variable like that. I need some help with that. Also, Can we use this code for xtreg as I have a panel data? Thanks.

        Comment


        • #5
          I am weighting for treating heterosckedasticity.

          Comment


          • #6
            Rajan Dhakal , if you look into Jeff's classic textbook "Introductory Econometrics: A Modern Approach (7e)", chapter 8-4b lists a feasible GLS procedure to correct for heteroskedasticity. The estimated variance for weighting is generated from auxiliary regressions. Below please find an example (only for exercise) which shows how you could get the weight. Other than doing this "by hand", Stata's command -hetregress- may directly give the same results, also shown below.

            Code:
                sysuse auto, clear
            
            * WLS by hand
                reg price length i.foreign    //OLS
                predict r, r    //residual
                gen lrsq = ln(r^2)    //ln(residual^2)
            
                reg lrsq length        //auxiliary regression: assume the variance varies by length
                predict lrsqhat        
                gen h = exp(lrsqhat)    //estimate of the variance
            
                reg price length i.foreign [aw=1/h]        //WLS
            
            * WLS with -hetregress-
                hetregress price length i.foreign, het(length) twostep
            Part of the results:
            Code:
            . reg price length i.foreign [aw=1/h]             //WLS
            (sum of wgt is .00007419812346)
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(2, 71)        =     17.20
                   Model |  94395245.9         2    47197623   Prob > F        =    0.0000
                Residual |   194866917        71  2744604.46   R-squared       =    0.3263
            -------------+----------------------------------   Adj R-squared   =    0.3074
                   Total |   289262163        73  3962495.38   Root MSE        =    1656.7
            
            ------------------------------------------------------------------------------
                   price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  length |   66.70549   11.67666     5.71   0.000     43.42289    89.98809
                         |
                 foreign |
                Foreign  |   1580.511   428.8698     3.69   0.000     725.3689    2435.653
                   _cons |  -6934.138   2085.765    -3.32   0.001    -11093.03   -2775.241
            ------------------------------------------------------------------------------
            
            .
            . * WLS with -hetregress-
            . hetregress price length i.foreign, het(length) twostep
            
            Heteroskedastic linear regression               Number of obs     =         74
            Two-step GLS estimation
                                                            Wald chi2(2)      =      34.39
                                                            Prob > chi2       =     0.0000
            
            ------------------------------------------------------------------------------
                   price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
            price        |
                  length |   66.70549   11.67666     5.71   0.000     43.81966    89.59132
                         |
                 foreign |
                Foreign  |   1580.511   428.8698     3.69   0.000     739.9416     2421.08
                   _cons |  -6934.137   2085.765    -3.32   0.001    -11022.16   -2846.113
            -------------+----------------------------------------------------------------
            lnsigma2     |
                  length |   .0448232   .0116768     3.84   0.000     .0219371    .0677094
                   _cons |   7.122623   2.209595     3.22   0.001     2.791897    11.45335
            ------------------------------------------------------------------------------
            Wald test of lnsigma2=0: chi2(1) = 14.74                  Prob > chi2 = 0.0001
            In practice, we often simply use heterokedasticity-robut standard errors, unless you are able to correctly specify the form of heteroskedasticity. Below is an example in practice.

            Code:
            reg price length i.foreign, vce(robust)
            When you use -xtreg- with, for example, fixed effects, you may need to cluster the standard error at the panel level -- But this case is identical to using -vce(robust)-.

            Code:
            * Identical results
                xtreg y x, fe vce(cluster panelid)
                xtreg y x, fe vce(robust)

            Comment


            • #7
              Fei Wang Thank you for the help. This is exactly what I needed.

              Comment

              Working...
              X