Announcement

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

  • Combining statsby with a rolling window regression

    Dear all,

    I am trying to combine statsby with a rolling window regression. Unfortunately, I didn't figure out a feasible command. I tried the following:
    Code:
    statsby _b, by(Ind) clear: reg eret IP MktRF HML SMB, wind(date_adj 72)
    My data looks as following:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float date_adj str6 Ind float IP double(MktRF SMB HML) float eret
    24 "_Aero"  -.8879781 -3.87  1.86 4.98   6.78
    24 "_Agric" -.8879781 -3.87  1.86 4.98  -3.66
    24 "_Autos" -.8879781 -3.87  1.86 4.98  -1.27
    24 "_Banks" -.8879781 -3.87  1.86 4.98  -6.16
    24 "_Beer"  -.8879781 -3.87  1.86 4.98  -3.45
    24 "_BldMt" -.8879781 -3.87  1.86 4.98  -5.71
    24 "_Books" -.8879781 -3.87  1.86 4.98  -3.81
    24 "_Boxes" -.8879781 -3.87  1.86 4.98  -5.38
    24 "_BusSv" -.8879781 -3.87  1.86 4.98  -1.45
    24 "_Chems" -.8879781 -3.87  1.86 4.98  -4.76
    24 "_Chips" -.8879781 -3.87  1.86 4.98  -4.53
    24 "_Clths" -.8879781 -3.87  1.86 4.98  -5.89
    24 "_Cnstr" -.8879781 -3.87  1.86 4.98  -1.32
    24 "_Coal"  -.8879781 -3.87  1.86 4.98   4.67
    end
    format %tm date_adj
    I am happy about any help.

    Best,
    Alex

  • #2
    I don't know what the -wind()- option is supposed to be. Neither -regress- nor -statsby- has such an option. (And if it is intended as an option to -statsby- it is in the wrong place anyway.) There is a -window()- option in -rolling-, but that is a different command altogether. In -rolling-, the -window()- option takes only a single argument: the number of consecutive observations to be incuded. So I'm not sure what kind of window you're trying to construct here. My first thought is that you wanted to include all observations where date_adj is within 1 to 72 days before the value of date_adj in the index observation, but in your example data, date_adj shows no variation at all (and does not appear to be a date). But on the assumption that this is what you wanted, you can do this easily with:

    Code:
    rangestat (reg) eret IP MkrtRF HML SMB, by(Ind) interval(date_adj -72 -1)
    Note: Not tested. Requires that you install the -rangestat- command, written by Robert Picard, Nick Cox, and Roberto Ferrer, and available from SSC.

    Comment


    • #3
      Thank you Clyde. I will have a try.

      Comment

      Working...
      X