我试图检查Stata是否正在使用我之前reg
中使用的模型NormalReg(样本模型)中的初始值。但是,在我看来,通过查看迭代0,它没有考虑我的初始值。任何有助于解决此问题的帮助都将受到高度赞赏。
set seed 123
set obs 1000
gen x = runiform()*2
gen u = rnormal()*5
gen y = 2 + 2*x + u
reg y x
Source | SS df MS Number of obs = 1000
-------------+------------------------------ F( 1, 998) = 52.93
Model | 1335.32339 1 1335.32339 Prob > F = 0.0000
Residual | 25177.012 998 25.227467 R-squared = 0.0504
-------------+------------------------------ Adj R-squared = 0.0494
Total | 26512.3354 999 26.5388743 Root MSE = 5.0227
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x | 1.99348 .2740031 7.28 0.000 1.455792 2.531168
_cons | 2.036442 .3155685 6.45 0.000 1.417188 2.655695
------------------------------------------------------------------------------
cap program drop NormalReg
program define NormalReg
args lnlk xb sigma2
qui replace `lnlk' = -ln(sqrt(`sigma2'*2*_pi)) - ($ML_y-`xb')^2/(2*`sigma2')
end
ml model lf NormalReg (reg: y = x) (sigma2:)
ml init reg:x = `=_b[x]'
ml init reg:_cons = `=_b[_cons]'
ml max,iter(1) trace
ml max,iter(1) trace
initial: log likelihood = -<inf> (could not be evaluated)
searching for feasible values .+
feasible: log likelihood = -28110.03
rescaling entire vector .+.
rescale: log likelihood = -14623.922
rescaling equations ...+++++.
rescaling equations ....
rescale eq: log likelihood = -3080.0872
------------------------------------------------------------------------------
Iteration 0:
Parameter vector:
reg: reg: sigma2:
x _cons _cons
r1 3.98696 1 32
log likelihood = -3080.0872
------------------------------------------------------------------------------
Iteration 1:
Parameter vector:
reg: reg: sigma2:
x _cons _cons
r1 2.498536 1.773872 24.10726
log likelihood = -3035.3553
------------------------------------------------------------------------------
convergence not achieved
Number of obs = 1000
Wald chi2(1) = 86.45
Log likelihood = -3035.3553 Prob > chi2 = 0.0000
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
reg |
x | 2.498536 .2687209 9.30 0.000 1.971853 3.02522
_cons | 1.773872 .3086854 5.75 0.000 1.16886 2.378885
-------------+----------------------------------------------------------------
sigma2 |
_cons | 24.10726 1.033172 23.33 0.000 22.08228 26.13224
------------------------------------------------------------------------------
Warning: convergence not achieved
答案 0 :(得分:2)
显然,如果您希望ml
在迭代0处评估指定初始值的可能性,则还必须为sigma2
;提供值。将代码的最后一部分更改为:
matrix rmse = e(rmse)
scalar mse = rmse[1,1]^2
ml model lf NormalReg (reg: y = x) (sigma2:)
ml init reg:x = `=_b[x]'
ml init reg:_cons = `=_b[_cons]'
ml init sigma2:_cons = `=scalar(mse)'
ml maximize, trace
请注意,sigma ^ 2的ML估计值与均方根误差不同,因为ML不知道自由度。 n = 1,000 sigma2 =(998/1000)* rmse。
答案 1 :(得分:1)
program
的确切位置看到。这可能会被几个不同的行动直接或间接地破坏。最好将要用作参数的参数视为在运行时使用程序选项提供给程序的参数。