5# sungmoo
總結兩位老師的解答,問題得以解決,舉例如下(附do文件及結果):
reg y x1-x6 與 reg y x1-x6,beta 結果回歸係數一樣,但前者沒有顯示標準回歸係數,並且後者的標準係數也沒有辦法貯存在變量或matrix中,這是我比較關心的
但通過將數據標準化後,reg y x1-x6與reg y x1-x6,beta結果便一樣,並且reg y x1-x6,beta中回歸係數和標準回歸係數是相同的,並且mat a=e(b) 可以引用標準回歸係數(實質上我引用的是與標準回歸係數相同的回歸係數)
不知對否,請各位老師指正!
另外我還有一個不會用,比如我想把結果中的每個標準係數存在scalar a1 a2...,不知怎麼實現,請老師們指導!
capture sysuse auto,clear
drop mpg
drop rep78
drop headroom
drop trunk
drop turn
drop foreign
egen sprice=std(price),mean(0) std(1)
egen sw=std(weight),mean(0) std(1)
egen sl=std(length),mean(0) std(1)
egen sd=std(disp),mean(0) std(1)
egen sg=std(gear),mean(0) std(1)
reg price weight length displacement gear_ratio
reg price weight length displacement gear_ratio,beta
reg sprice sw sl sd sg,beta
ereturn list
mat a=e(b)
matlist a
結果如下,
. reg price weight length displacement gear_ratio
Source SS df MS Number of obs = 74
F( 4, 69) = 11.04
Model 247810070 4 61952517.6 Prob > F = 0.0000
Residual 387255326 69 5612396.02 R-squared = 0.3902
Adj R-squared = 0.3549
Total 635065396 73 8699525.97 Root MSE = 2369
price Coef. Std. Err. t P>t [95% Conf. Interval]
weight 4.915578 1.367776 3.59 0.001 2.18694 7.644216
length -103.8873 38.64346 -2.69 0.009 -180.9788 -26.79567
displacement 9.570863 7.893187 1.21 0.229 -6.175615 25.31734
gear_ratio 2395.815 1091.898 2.19 0.032 217.537 4574.092
_cons 1735.29 5817.673 0.30 0.766 -9870.649 13341.23
. reg price weight length displacement gear_ratio,beta
Source SS df MS Number of obs = 74
F( 4, 69) = 11.04
Model 247810070 4 61952517.6 Prob > F = 0.0000
Residual 387255326 69 5612396.02 R-squared = 0.3902
Adj R-squared = 0.3549
Total 635065396 73 8699525.97 Root MSE = 2369
price Coef. Std. Err. t P>t Beta
weight 4.915578 1.367776 3.59 0.001 1.295257
length -103.8873 38.64346 -2.69 0.009 -.7842659
displacement 9.570863 7.893187 1.21 0.229 .2980039
gear_ratio 2395.815 1091.898 2.19 0.032 .3706326
_cons 1735.29 5817.673 0.30 0.766 .
. reg sprice sw sl sd sg,beta
Source SS df MS Number of obs = 74
F( 4, 69) = 11.04
Model 28.4854684 4 7.1213671 Prob > F = 0.0000
Residual 44.514532 69 .645138145 R-squared = 0.3902
Adj R-squared = 0.3549
Total 73.0000004 73 1.00000001 Root MSE = .8032
sprice Coef. Std. Err. t P>t Beta
sw 1.295257 .3604096 3.59 0.001 1.295257
sl -.7842659 .2917273 -2.69 0.009 -.7842659
sd .2980039 .2457669 1.21 0.229 .2980039
sg .3706326 .1689167 2.19 0.032 .3706326
_cons 3.13e-09 .0933707 0.00 1.000 .
. ereturn list
scalars:
e(N) = 74
e(df_m) = 4
e(df_r) = 69
e(F) = 11.03851501263808
e(r2) = .3902118936857077
e(rmse) = .8032049208933202
e(mss) = 28.48546839290257
e(rss) = 44.51453200135989
e(r2_a) = .3548618585370531
e(ll) = -86.19622382315104
e(ll_0) = -104.4980425309136
e(rank) = 5
macros:
e(cmdline) : "regress sprice sw sl sd sg,beta"
e(title) : "Linear regression"
e(marginsok) : "XB default"
e(vce) : "ols"
e(depvar) : "sprice"
e(cmd) : "regress"
e(properties) : "b V"
e(predict) : "regres_p"
e(model) : "ols"
e(estat_cmd) : "regress_estat"
matrices:
e(b) : 1 x 5
e(V) : 5 x 5
functions:
e(sample)
. mat a=e(b)
. matlist a
sw sl sd sg _cons
y1 1.295257 -.7842659 .2980039 .3706326 3.13e-09