Announcement

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

  • Rolling regressions, monthly intervals using daily data

    Hi there,

    I'm trying to compute coefficient estimates using rolling regressions on daily CRSP stock data at monthly intervals. Specifically, I'd like to start the regressions on the first day of each new month and use the daily observations for each of the prior six months. The output I'm looking for is a single coefficient estimate for each month.

    Here's my first take on the code:

    Code:
    rolling _b, window(126) stepsize(21): reg excess_ret MKT
    The data only contains trading days, not calendar days, so 126 is the average number of trading days per six month period, and 21 is the average number of trading days per month. The goal here is to compute beta estimates once per month using all of the daily observations over the prior six months.

    The problem with this is that there aren't exactly 126 trading days per six months, nor are there exactly 21 trading days per month. Is there a way to make this estimation more precise? For instance, on 01Jul2014, I would like the code to execute from 01Jan2014 to 30Jun2014, then step to 01Aug2014 and execute on 01Feb2014 to 31Jul2014, etc.

    I've also looked up variants of ''rolling'' such as rolling2 and rollreg, but don't see any of them being flexible enough to do this. The solution might involve ditching ''rolling'' and writing custom loops.

    Any and all help much appreciated!

  • #2
    Dear Robert,

    I trust you are doing well. I am wondering have you got the code to estimate rolling window regression on daily data at monthly intervals? If yes, could you please share me your Stata code? I have the same problem too. Many thanks in advance.

    Have a good day.

    Best wishes,
    Catherine

    Comment


    • #3
      Some general advice here:

      1. Read -help business calendars- and the associated entry in the PDF Manual that comes with your Stata installation. It will allow you to convert your date variables in such a way that managing the calendar irregularities is easier.

      2. Once you have done that, look at the -rangestat- command, by Robert Picard, Nick Cox, & Roberto Ferrer. It is available from SSC. This command had not yet been written at the time of the original post in this thread. It greatly simplifies and speeds up rolling window analyses like this.

      I don't myself use business calendars in my work, so I'm not familiar enough with them to offer you specific code, and, in any case, no example data has been given to work with. But I believe that implementing this with the combination of business calendars and -rangestat- won't require more than 3 or 4 lines of code, and maybe even just two.

      Correction: On thinking further, it isn't clear that using business calendars will be helpful here. They solve other problems, but in this case you really want to select your estimation samples based on ordinary calendar time periods. -rangestat- should handle this nicely with the already existing dates. The key to defining a 6 month window will be extracting the monthly dates from the daily dates you are starting with. That is what the -mofd()- function does. Setting the -interval(monthly_date -1 -6)- should do the trick. And to identify which dates are the first of the month, the boolean expression would be -date == dofm(mofd(date))-, or, equivalently, -day(daily_date) == 1-.
      Last edited by Clyde Schechter; 22 Feb 2018, 12:43.

      Comment


      • #4
        Dear Professor Schechter,

        Many thanks for your kind quick comments. It's highly appreciated.

        I found the -rangestat- command works very well to estimate rolling window regression on daily data at monthly or yearly intervals. The following are my demonstration commands:

        ----- ssc install rangestat
        ----- help rangestat

        ----- webuse grunfeld, clear
        ----- rangestat (reg) mvalue invest , interval(year -4 0) by(company)


        I hope this also helps to other Stata users.

        Many thanks for all your support, again.

        Have a good day.

        Best wishes,
        Catherine
        Last edited by Catherine Bloom; 23 Feb 2018, 08:13.

        Comment

        Working...
        X