Announcement

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

  • rolling monthly (fixed window) stats via Rangestat (SSC)

    Hi there, I am trying to calculate the rolling standard deviation, skewness and kurtosis via Rangestat (SSC) by using the below code for a fixed window of 12 months, but I am unable to get the fixed window and it is giving results from 2 months till reached to 12 and then 12 onwards for each ID. so I added some more steps to restrict it to 12 months only. Please advise if that is the right way of doing this or I can find the fixed window directly via Rangestat. any help would be appreciated. Regards, Sara
    Code:
    isid ID modate1, sort
    rangestat (sd) sd_ret=RET (skewness) sk_ret=RET (kurtosis) kr_ret=RET (count) cmnth=RET, interval(modate1 -11 0) by(ID)
    Code:
    /**To use only 12 months rolling stats**/
    clonevar cmnth1 = cmnth
    replace cmnth1 = . if cmnth1 < 12
    clonevar sd_ret1 = sd_ret
    replace sd_ret1 = . if cmnth < 12
    clonevar sk_ret1 = sk_ret
    replace sk_ret1 = . if cmnth < 12
    clonevar kr_ret1 = kr_ret
    replace kr_ret1 = . if cmnth < 12

  • #2
    -rangestat- is designed so that it will calculate the statistics based on whatever observations meet the criterion that modate1 differs from the current modate1 by an amount that is between -11 and 0, inclusive. That happens whether there are 12 such observations, or 1, or 15, or whatever. So, as you noted, the next step when you only want results when there are 12 observations, is to replace the unwanted results with missing values. But your code does not do that. This code will:
    Code:
    foreach v of varlist sd_ret sk_ret kr_ret {
        replace `v' = . if cmnth != 12
    }

    Comment


    • #3
      Thanks heaps, Clyde it is very helpful, much appreciated.

      Comment

      Working...
      X