Announcement

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

  • quarterly rolling window four factor alphas out of monthly data

    Hello everyone,
    my problem, besides not knowing how to use stata, is the following:

    I have a dataset which includes:
    Date - end of month date from 01/2008-12/2016
    FundNo - identifies a fund
    monthly return of the fund
    monthly market excess return
    monthly smb return
    monthly hml return
    monthly umd return

    what I want to do:
    1) I want to estimate regression constants each month, using a 60 month (5years) window for each FundNo, I don't care about the other coefficients
    2) I want to sum these monthly alphas (2013-2016 - 48 estimates per FundNo) together to have quarterly instead of monthly estimates

    my result variable:
    I would have a new variable "alpha" which shows the summed regression constant every three months (March, June, September, December) for each FundNo (which I am then able to merge with my other dataset based on quarterly data via identifier "FundNoDate")

    I have searched the forum already and found a mata code, which is supposed to help with similar problems, but I honestly have no idea how to alter codes for my purpose.

    I appreciate your help a lot!

  • #2
    Robert Picard, Nick Cox, and Roberto Ferrer's -rangestat- command has been updated so that it now can do rolling regressions without requiring you to code the regression in Mata. If you don't already have it, run -ssc install rangestat-, and do read the help file to get a fuller sense of what it can do and how it works. If you have the earlier version that did not support Stata regression commands, get the update.

    You do not explain exactly what is in your desired regression. So I'll assume you want to regress excess return against smb, hml, and umd returns (whatever those are!) You also don't show your data. I'll assume that the variable Date is a Stata internal format daily date variable. (If it isn't, you need to convert it to that before proceeding.) You also don't say if you want your 60 month window to end on the month of the observation or to constitute the 60 strictly preceding months. I'll assume the latter. So it would go like this:

    Code:
    //  CREATE A MONTHLY DATE VARIABLE TO INDEX THE WINDOW
    gen mdate = mofd(Date)
    format mdate %tm
    
    //  ROLLING REGRESSIONS
    rangestat (reg) excess_return smb_return hml_return umd_return, by(FundNo) interval(mdate -60 -1)
    rename b_cons alpha
    
    // CREATE A QUARTERLY DATE AND AGGREGATE (SUM) ALPHA UP TO QUARTERLY LEVEL
    gen qdate = qofd(Date)
    format qdate %tq
    collapse (sum) alpha, by(qdate FundNo)
    Note: Not tested. Beware of typos, etc.

    Note also that the results here will be indexed by a quarterly date and FundNo. To -merge- it into your other data set, I suggest you create a corresponding quarterly date there for use in the -merge- key. Assuming that the other data set has a Date variable that is a daily date corresponding to the final day of the quarter, the- qofd()- function will serve, just as in the code shown here.

    Comment


    • #3
      Hello Clyde, first of all, thank you for your time and your answer! your assumptions regarding my intentions were correct. I have run the code now and it worked! I have checked back two funds and two time intervals to verify. I will convert the other dataset date variable with the qofd() function for merging. you really helped my progress a lot! thank you!

      Comment

      Working...
      X