Announcement

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

  • Out-of-sample R^2

    I am struggling to compute my out-of-sample results for R^2os. This is out-of-sample R^2 as done by Campbell and Thompson (2008), as
    1 - sum[(r_t - rhat_t)^2] / sum[(r_t - rbar_t)^2] , where rhat is the fitted value from a predictive regression, rbar is the historical average return.

    I have tried this code so far but my results do not match those I am trying to replicate.

    My initial period is t<205 to forecast from t= 205 to 504.

    regress r1 DPs if t<205
    predict fittedDPs
    gen feDPs = r1 - fittedDPs if t>=205
    gen sfeDPs = feDPs^2
    gen sumsfeDPs = sum(sfeDPs)

    regress r1 if t<205
    predict historic
    gen fehist = r1 - historic if t>=205
    gen sfehist = fehist^2
    gen sumsfehist = sum(sfehist)


    I then compare the last values at t=504 of the summed variables as the R^2os states as = 1 - sum[(r_t - rhat_t)^2] / sum[(r_t - rbar_t)^2]
    so 1 - sumsfeDPs/sumsfehist, at t=504.

    However I am not producing the correct results.

    Any help would be greatly appreciated.

  • #2
    You will increase your chances of useful answer by following the FAQ on asking questions – provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Being able to replicate your problem and play with the data is really helpful, particularly when were trying to debug a calculation. While you have tried to show us what you did, it would be a lot better if it were right out of your program in code delimiters.

    It would really help if where had a set of data where you knew what the out of sample R squared is so that we could mess with the function.

    If you're calculating a single number, then it is probably much better to use macros or scalars than generate. Note also that generate with sum gives you a running sum rather than a sum across the entire sample. Egan can give you a sum across the entire sample. I also have trouble understanding what you're trying to do since your equation seems to have a sum divided by exactly the same sum which makes no sense. Both the equation at the top of your posting and your coding near the bottom seem to come out to zero for all values.

    It is not clear to me what you mean by R-square-os. You are running two different models - it seems very strange that you would run two different models and then try to calculate an R squared.

    Comment

    Working...
    X