Announcement

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

  • Code for out of sample R-squared?

    Hi all. I'm writing a thesis and I need to calculate out-of-sample R-squared, taking the form:
    Click image for larger version

Name:	QQ截图20170921164428.png
Views:	1
Size:	11.6 KB
ID:	1411317

    rt is regressand; rt_bar is average of the reggresaand up to time t; rt_hat is the predicted value of r based on regression using data from t=1~t-1

    I'll need an initial sample to for predicting r_hats. So basically, after using data on the first, say, 180 observations, I predict a r_181_hat, this is the r1_hat in the formula; then for each of the next observations, I regress r on regressors using all available data up to t, predict the next period's value, etc etc. So may I have some suggestion how to code in Stata to recursively do the regression using Stata and generate one-period ahead r_hat? Thank you.



  • #2
    There is an official Stata command, -rolling- which will do recursive rolling regressions. There is also Robert Picard, Nick Cox, and Roberto Ferrer's -rangestat-, available from SSC. Personally, I prefer the latter. The help file has a worked example.

    Comment

    Working...
    X