小弟现在在作一个code,其主要步骤是先在每一个时间t(t=1,2,….480)提取所有的regressors,得到480行并且将它们每个都转置后做成480个Vector,每个vector是50×1,然后用主成分分析的方法分析原始的50个regressors,并得到他们的因子载荷,用因子载荷乘以上述这个vector得到factor,再用原来的dependent variable y_cpi_`h’ 与这些factors 做回归。并且得到预测序列
下面这个循环是提取每个vector的过程
forvalues i = 1(1)480
{
preserve
keep if [_n] == `i'
mkmat by*, mat(trans_x_`i')
mat x_`i' = (trans_x_`i')'
restore
}
之后这个循环是对于每一个不同forecast horizon 1,3, 6, 12, 18, 24, 30, 36,取不同个数的主成分1,2,3,4,完成我上述描述的过程,,但是stata会报错说“x_ not found”我的理解是他找不到x_`i’ 这个矩阵,所以在用因子载荷乘以x_`i’,的时候会出现问题,但是我在stata里面mat list x_1,他却能显示出一个50×1的矩阵,我感到十分困惑,既然stata内存里已经有x_`i’这个矩阵(加粗的那行),为什么他还会报错呢?请求连老师的解答,非常感谢
foreach h of numlist 1 3 6(6)36
{
preserve
keep if y_cpi_`h'!=.
forvalues k = 1/4
{
* principal component analysis
display "applying the pca with the restriction there are `k' principal components"
pca by*, comp(`k')
* Factor loadings
mat loadings_`h'_`k' = e(L)
* CF- factors estimation
display "These are the regressions with PCs when forecast horizons are `h' periods"
mat f_hat_CF_`h'_`k' = (loadings_`h'_`k')'* (x_`i')
* Regression
display "These are the regressions with PCs when forecast horizons are `h' periods"
qui regress y_cpi_`h' f_hat_CF_`h'_1-f_hat_CF_`h'_`k'
scalar CI_PC_R_square_y_cpi_`h' = e(r2)
scalar CI_PC_RSS_y_cpi_`h' = e(rss)
}
restore
}


雷达卡




京公网安备 11010802022788号







