Announcement

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

  • Obtaining 5 year rolling standard deviation of RET

    Hello everyone:

    I am calculating the estimate of stock volatility, which use annualized standard deviation of stock returns estimated over the 60 months prior to the beginning of the fiscal period.

    So I download the monthly data from CRSP.
    And I run the code below:

    rangestat (sd) ret, interval(date -60 0) by(cusip) But however the results I got is not what I want, I want at least 60 months to run the standard deviation, but however this code run sd even when you only have two month data. So is there anyway to strict the command that the loop have to be 60 months? Thank you very much. Lucas

  • #2
    Code:
    rangestat (sd) ret (count) ret, interval(date -60 0) by(cusip)
    replace ret_sd = . if ret_count < 60
    will do that.

    I'll just note that since your window is 61 months, requiring that there be at least 60 of them is a very strict criterion.
    Last edited by Clyde Schechter; 06 Mar 2019, 15:41. Reason: Correct error in code.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      rangestat (sd) ret (count) ret, interval(date -60 0) by(cusip)
      replace ret_sd = . if ret_count < 60
      will do that.

      I'll just note that since your window is 61 months, requiring that there be at least 60 of them is a very strict criterion.

      Hello Clyde:
      Thanks for your reply.

      I just used your code, but find out that when I count ret, the highest number I got from ret_count is 3, so all my ret_sd are equal .

      I know that it's weird that we need 60 months rolling, but I am following the steps as follow:

      we (i) use
      annualized standard deviation of stock returns estimated over the 60
      months prior to the beginning of the fiscal period; (ii) require at least
      12 months of returns data; (iii) use mean volatility (across all firms)
      for that year if 12 months of data are not available; and (iv) winsorize
      the volatility estimates at the 5th and 95th levels

      Comment


      • #4
        I think you need to show your example data. The code clearly calls for a window of 61 months--and even if you have a typical amount of missing data, getting a maximum of 3 suggests something is wrong.

        Here is one possibility: the code assumes that your date variable is a Stata internal format monthly date. But perhaps you are using daily dates that are spaced a month apart. In that case, Stata will look over a window of 61 days, and since the current date is counted, that would get you only 3 observations. If that's the case you need to convert your daily dates to monthly dates. If you need help with that, post back and use the -dataex- command to show an example of your data. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

        Comment

        Working...
        X