Announcement

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

  • Using rolling regression

    Dear all,

    I run a rolling regression for each equity every 12 months by using a market model.
    The purpose of my rolling regression is to obtain the standard deviation of residuals (idiosyncratic risk) and standard deviation of predicted values (systematic risk) for each firm every year.
    I know that rmse stands for the standard deviation of residuals.
    However, could anyone tell me what code can be used for standard deviation of predicted values.

    Thank you!

  • #2
    There is nothing returned in e() after regress that gives you the standard deviation of the predicted values. You will have to calculate it directly after the regression:

    Code:
    predict yhat, xb
    summ yhat
    and the standard deviation will be in r(sd).

    Since you are trying to do this on a rolling basis, if you are currently using a -regress- command with the -rolling- prefix, you will probably need to instead write a short program to use with -rolling:-. Or, you could do this using Robert Picard's new -rangerun- command (available from SSC) instead of -rolling:-. Most likely -rangerun- will execute much faster if you are working with a very large data set.

    Comment


    • #3
      Hi Clyde,

      Thank you.
      But I didn't use codes to execute the regression.
      I run the regressions through "statistics">> "Time series" >> "Rolling-window and recursive estimation"
      The following is the screenshot.
      I don't know how to write expressions for the standard deviation in the red box.

      Click image for larger version

Name:	sreenshot.PNG
Views:	1
Size:	41.0 KB
ID:	1400947

      Comment


      • #4
        OK. I don't think you can do this just using the GUI. You're going to have to use code in a do-file, and you're going to have to write a program. Not having shown any example data, I can only offer limited help, with an example based on a publicly available Stata data set:

        Code:
        clear*
        
        capture program drop myprogram
        program define myprogram
            regress mvalue kstock
            gen idosyncratic_risk = e(rmse)
            predict xb, xb
            summ xb
            gen systematic_risk = r(sd)
            drop xb
            exit
        end
        
        
        webuse grunfeld
        rangerun myprogram, by(company) interval(year -2 0) use(mvalue kstock)
        To do this, you will have to install Robert Picard and Nick Cox's -rangerun- program. Run -ssc rangerun-. I believe that you also need to install -rangestast- in order for -rangerun- to work. (-rangestat- is also from SSC.)

        Evidently you will need to modify -myprogram- to customize it to your own situation. Similarly, in the -rangerun- command itself, I have set the window to 3 years (from 2 years before to the current year, inclusive): you are working with monthly data and will want -interval(monthly_date, -11, 0)- or -interval(monthly_date, -12, -1)- depending on whether your 12 month window ends with or just before the current month.

        Comment

        Working...
        X