Hi everyone!
I am trying to graph the performance of in-sample and out-of-sample variables. For the IS regressions, the performance is the cumulative squared demeaned equity premium minus the cumulative squared regression residual. For the OOS regressions, this is the cumulative squared prediction errors of the prevailing mean minus the cumulative squared prediction error of the predictive variable from the linear historical regression.
I run the code that I have for different variables but the graph looks the same for all the variables. This means that the residuals are the same for all the regressions, which is not realistic for different variables.
This is what I have so far:
newey ret_av12 un_ch1, lag(1)
predict retHAT
gen residuals=ret_av12-retHAT
gen re_sq= residuals^2
gen cum_sum=sum(re_sq)
egen mean_ret=mean(ret_av12)
gen demean_ret= ret_av12-mean_ret
gen demean_ret_sq= demean_ret^2
gen cum_demean= sum(demean_ret_sq)
gen performance_IS= cum_demean-cum_sum
tsline performance_IS
drop performance_IS cum_demean demean_ret_sq demean_ret mean_ret cum_sum re_sq residuals retHAT
//OOS line un_ch1
forvalues t=240/695 {
newey ret_av12 un_ch1 if dm<`t', lag(1),
predict retHAT_`t' if inrange(dm, dm[`'+1], dm[`'+1])
}
egen ret_HAT_=rowtotal(retHAT_240-retHAT_695)
gen res= ret_av12-ret_HAT_ if dm>240
gen res_sq= res^2
gen cum_sum1=sum(res_sq)
gen performance_OOS=cum_sum1-cum_sum
tsline performance_IS performance_OOS
drop residuals re_sq cum_sum mean_ret demean_ret cum_demean performance_IS e_hat e_sq cum_sum1
I run the same regression by replacing the un_ch1 variable with others and I get the same graph.
Does anyone know what is wrong with my code?
I am trying to graph the performance of in-sample and out-of-sample variables. For the IS regressions, the performance is the cumulative squared demeaned equity premium minus the cumulative squared regression residual. For the OOS regressions, this is the cumulative squared prediction errors of the prevailing mean minus the cumulative squared prediction error of the predictive variable from the linear historical regression.
I run the code that I have for different variables but the graph looks the same for all the variables. This means that the residuals are the same for all the regressions, which is not realistic for different variables.
This is what I have so far:
newey ret_av12 un_ch1, lag(1)
predict retHAT
gen residuals=ret_av12-retHAT
gen re_sq= residuals^2
gen cum_sum=sum(re_sq)
egen mean_ret=mean(ret_av12)
gen demean_ret= ret_av12-mean_ret
gen demean_ret_sq= demean_ret^2
gen cum_demean= sum(demean_ret_sq)
gen performance_IS= cum_demean-cum_sum
tsline performance_IS
drop performance_IS cum_demean demean_ret_sq demean_ret mean_ret cum_sum re_sq residuals retHAT
//OOS line un_ch1
forvalues t=240/695 {
newey ret_av12 un_ch1 if dm<`t', lag(1),
predict retHAT_`t' if inrange(dm, dm[`'+1], dm[`'+1])
}
egen ret_HAT_=rowtotal(retHAT_240-retHAT_695)
gen res= ret_av12-ret_HAT_ if dm>240
gen res_sq= res^2
gen cum_sum1=sum(res_sq)
gen performance_OOS=cum_sum1-cum_sum
tsline performance_IS performance_OOS
drop residuals re_sq cum_sum mean_ret demean_ret cum_demean performance_IS e_hat e_sq cum_sum1
I run the same regression by replacing the un_ch1 variable with others and I get the same graph.
Does anyone know what is wrong with my code?