Announcement

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

  • Rolling window regression - asreg

    Dear Stata Users,

    I am trying to calculate 5-year rolling window regression using mothly data with a minimum requirement of 2 years. For this I use the following code:

    Code:
    bys permno: asreg ret_rf mean_mrkt_year, wind(fdate 60) min(24)
    What I am struggling with is that I dont understand whether "asreg" calulates trailing betas. For example , if estimated beta for Sep, 1990 is 0.2 does it mean that it started the regression from Aug 1990 over 59 month? What I need is a trailing beta, like for a given firm-date observation there should be a beta_estimated starting from the previos observation till -60th.

    Please, advise me this issue.

  • #2
    Ataullah Shah, who is the author of -asreg- is an active member of this Forum and will probably respond to your question when he is next on. He is very attentive to questions about his program here.

    That said, if you are in a rush, you can also do your rolling regression using -rangestat-:

    Code:
    rangestat ret_rf mean_mrkt_yr, by(permno) interval(fdate -60 -1)
    -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer and is available from SSC.

    This approach will not impose the minimum 24 month restriction, but it will return a variable in your data set how many observations were used in estimating each regression, and you can then either -drop- the ones with too few, or clobber their coefficient variables with missing values.

    Comment


    • #3
      In asreg, if the window is 60, it means that the current observation plus previous 59 observation will be used in finding the regression estimates. So in your case, the results reported are not for the previous 59 observations, they are for 60 observations. If you want to exclude the current observation from the window, then there is a way if your data is panel data and has been tsset or xtset. We shall estimate the rolling regression using a window of 59 observations and then lag the generated coefficients by one lag.

      In the following example, I am using a window of 9 observations and then lag the beta by one to match it with the next observation in the data set.

      Code:
      webuse grunfeld, clear
      bys company : asreg invest mvalue , wind( year 9) min(5)
      ren _b_mvalue beta
      drop _*
      gen trail_beta = L.beta
      drop beta
      list in 1/10
           +-------------------------------------------------------------+
           | company   year   invest   mvalue   kstock   time   trail_~a |
           |-------------------------------------------------------------|
        1. |       1   1935    317.6   3078.5      2.8      1          . |
        2. |       1   1936    391.8   4661.7     52.6      2          . |
        3. |       1   1937    410.6   5387.1    156.9      3          . |
        4. |       1   1938    257.7   2792.2    209.2      4          . |
        5. |       1   1939    330.8   4313.2    203.4      5          . |
           |-------------------------------------------------------------|
        6. |       1   1940    461.2   4643.9    207.2      6   .0523369 |
        7. |       1   1941      512   4551.2    255.2      7    .061027 |
        8. |       1   1942      448   3244.1    303.7      8   .0694259 |
        9. |       1   1943    499.6   4053.7    264.1      9   .0510168 |
       10. |       1   1944    547.5   4379.3    201.6     10   .0505237 |
           +-------------------------------------------------------------+
      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


      • #4
        Thank you very much for your help!

        Comment


        • #5
          Clyde Schechter . if we want regression we should add (reg) after rangestat right?

          rangestat(reg) ret_rf mean_mrkt_yr, by(permno) interval(fdate -60 -1) thanks for pointing out that command and the asreg is also very nice Attaullah

          Comment


          • #6
            Wessel de Kroo Yes, that is right. My apologies for the error.

            Comment


            • #7
              ha, made my day not problem at all , especially coming from you

              Comment


              • #8
                @Attaullah Shah, this trick might cause some problems when there are gaps (unbalanced) in the data.

                @Clyde Schechter, is it possible to compute rmse from the output of rangestat (reg)?

                Comment


                • #9
                  Yes, but it's not worth the effort. Instead of using -rangestat-, a simpler way to get this is:

                  Code:
                  webuse grunfeld, clear
                  
                  capture program drop one_company
                  program define one_company
                      regress mvalue kstock invest
                      foreach v of varlist kstock invest {
                          gen b_`v' = _b[`v']
                          gen se_`v' = _se[`v']
                      }
                      gen rmse = e(rmse)
                      gen r2 = e(r2)
                      exit
                  end
                  
                  runby one_company, by(company)
                  -runby- is written by Robert Picard and me, and is available from SSC.

                  Comment


                  • #10
                    Yuchen Luo I am not clear on what problems are you referring to. Even if there are gaps in the panel data and you are running a rolling regressions, asreg intelligently respects such gaps. To know more about the working of rolling window, please see this page. Though I have presented examples for asrol (from SSC) there, those examples are relevant for the new version of asreg.

                    If you are not running a rolling regression and want to find the rmse, then it is a case of group regressions. asreg can report rmse and other regression coefficients for groups. See the colored line in the following code.

                    Code:
                    webuse grunfeld, clear
                    
                    bys company : asreg invest mvalue , rmse se
                    
                    duplicates drop company, force
                    list _*
                    
                         +--------------------------------------------------------------------------------------------+
                         |     _rmse   _Nobs         _R2       _adjR2    _b_mvalue      _b_cons   _se_mv~e   _se_cons |
                         |--------------------------------------------------------------------------------------------|
                      1. | 234.38489      20   .45694051    .42677054    .23140906   -394.87099   .0594618   262.9737 |
                      2. | 112.48515      20   .23771359    .19536434    .20306231    10.071665   .0857087   170.8641 |
                      3. | 47.313197      20    .1015622    .05164899    .03741346    29.658314   .0262283   52.00507 |
                      4. | 36.641942      20   .30321234    .26450191    .14649317   -15.427027   .0523429    37.1982 |
                      5. | 8.8143652      20   .68003277    .66225682    .16938156    22.595751   .0273853   6.638225 |
                         |--------------------------------------------------------------------------------------------|
                      6. | 8.0203117      20   .95010279    .94733073    .15697064    -10.49548   .0084788   3.986171 |
                      7. | 18.518444      20   .03154031   -.02226301    .09878628    32.798303   .1290233   19.76503 |
                      8. | 10.688132      20   .70365843    .68719501    .07208201   -5.4690428   .0110257   7.773745 |
                      9. | 10.851506      20   .49623888    .46825215    .13569292   -3.3849416   .0322246   11.02215 |
                     10. | 1.7575607      20   .00926094   -.04578012   -.01783632    4.3494694   .0434832    3.10881 |
                         +--------------------------------------------------------------------------------------------+
                    .
                    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