Announcement

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

  • regressions with Newey–West standard errors for a list of countries

    I have a panel-data and I use ‘asreg’ or ‘rangestat’ to estimate a regression for each country separately. Instead of using the ordinary covariance method, I want to estimate OLS regressions with Newey–West standard errors robust to heteroskedasticity.
    For a single time series, the command below is used to estimate it in Stata.
    newey y x1 x2, lag(0)
    How can I apply this approach in ‘asreg’ or ‘rangestat’? or do you know any other method to estimate this regression for a large number of countries separately?
    Thanks.

  • #2
    Hi, im far from an expert but have you considered making a loop? Something in the lines of
    Foreach country in local countrylist
    reg...

    Hope it helps!

    Comment


    • #3
      rangestat and asreg are both commands from SSC. I can speak confidently for rangestat and less confidently for asreg, which is by Attaullah Shah.

      Newey-West standard errors are not supported directly by rangestat, which is not primarily a regression command but more a framework for window-related calculations that is also programmable. I don't doubt that you could write extra code in rangestat or its sibling rangerun to do what you want.

      In contrast asreg is billed as a regression command, rather than a programmable framework, and it does offer more regression bells and whistles. A glance at the help identifies a newey() option, but read the documentation carefully to see if it is what you want.

      Comment


      • #4
        Note that while a loop may be a good idea, #2 conflates two quite different syntaxes that can't be mixed.

        Code:
        foreach country of local countrylist
        is more likely to be what you want, although if country is a string variable that can be fiddly too.

        That said, there can be simpler ways to do it. https://www.stata.com/support/faqs/d...-with-foreach/ is not a complete discussion, as (e.g.) statsby is often overlooked.
        Last edited by Nick Cox; 17 Dec 2022, 06:16.

        Comment


        • #5
          Thank you Nick for tagging me in this post. Here is an example using asreg for cross-sectional regression with newey standard errors. Output from the official newey command is also posted for comparison. For a reasonably large dataset, forecch and statsby commands are slow enough to wear down one's patience. However, asreg is a breeze in usage and lightening in speed.
          Code:
           h asreg
          
          . webuse grunfeld, clear
          
          .  bys company: asreg invest mvalue kstock,  se newey(1)
          
          . keep if company == 1
          
          . tsset year
          
          .  newey invest mvalue kstock,  lag(1)
          
          Regression with Newey–West standard errors      Number of obs     =         20
          Maximum lag = 1                                 F(  2,        17) =      59.50
                                                          Prob > F          =     0.0000
          
          ------------------------------------------------------------------------------
                       |             Newey–West
                invest | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                mvalue |   .1192808   .0274023     4.35   0.000     .0614671    .1770946
                kstock |   .3714448   .0499277     7.44   0.000     .2661065    .4767831
                 _cons |  -149.7824   108.6338    -1.38   0.186    -378.9797    79.41486
          ------------------------------------------------------------------------------
          
          . list _*
          
               +----------------------------------------------------------------------------------------------------+
               | _Nobs         _R2      _adjR2   _b_mvalue   _b_kstock     _b_cons   _se_mv~e   _se_ks~k   _se_cons |
               |----------------------------------------------------------------------------------------------------|
            1. |    20   .92135403   .91210157   .11928082   .37144481   -149.7824   .0274023   .0499277   108.6338 |
          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment


          • #6
            On unrelated note, -newey- with 0 lags, which OP suggested he wants to do, is equivalent to robust. Here:

            Code:
            .  webuse idle2
            
            . 
            .         . tsset time
            
            Time variable: time, 1 to 30
                    Delta: 1 unit
            
            . 
            . 
            . newey usr idle, lag(0)
            
            Regression with Newey–West standard errors      Number of obs     =         30
            Maximum lag = 0                                 F(  1,        28) =      10.43
                                                            Prob > F          =     0.0032
            
            ------------------------------------------------------------------------------
                         |             Newey–West
                     usr | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                    idle |  -.2281501   .0706372    -3.23   0.003    -.3728437   -.0834564
                   _cons |   23.13483    6.43118     3.60   0.001     9.961153     36.3085
            ------------------------------------------------------------------------------
            
            . 
            . 
            . regress usr idle, robust
            
            Linear regression                               Number of obs     =         30
                                                            F(1, 28)          =      10.43
                                                            Prob > F          =     0.0032
                                                            R-squared         =     0.5006
                                                            Root MSE          =     2.7374
            
            ------------------------------------------------------------------------------
                         |               Robust
                     usr | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
            -------------+----------------------------------------------------------------
                    idle |  -.2281501   .0706372    -3.23   0.003    -.3728437   -.0834564
                   _cons |   23.13483    6.43118     3.60   0.001     9.961153     36.3085
            ------------------------------------------------------------------------------

            Comment


            • #7
              Joro Kolev
              Interesting! So if a user wants to use robust standard errors, here is the asreg code.
              Code:
              webuse idle2
              tsset time
              newey usr idle, lag(0)
              
              ------------------------------------------------------------------------------
                           |               Robust
                       usr | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
              -------------+----------------------------------------------------------------
                      idle |  -.2281501   .0706372    -3.23   0.003    -.3728437   -.0834564
                     _cons |   23.13483    6.43118     3.60   0.001     9.961153     36.3085
              ------------------------------------------------------------------------------
              
              . asreg usr idle, robust
              
              . list _*
              
                   +------------------------------------------------------------------------------+
                   | _Nobs         _R2      _adjR2      _b_idle     _b_cons   _se_idle   _se_cons |
                   |------------------------------------------------------------------------------|
                1. |    30   .50064502   .48281092   -.22815005   23.134828   .0706372    6.43118 |
              Regards
              --------------------------------------------------
              Attaullah Shah, PhD.
              Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
              FinTechProfessor.com
              https://asdocx.com
              Check out my asdoc program, which sends outputs to MS Word.
              For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

              Comment

              Working...
              X