benz1985 发表于 2012-10-16 09:53
不知道你能看明白吗?如何用stata进行编程,是否有相关的例子
受楼主召唤,自插双目扶墙而进,免得看到那令人蛋疼的标题而爆瞎。
楼主,你确认你的意思都表达完整清楚了么?
俺股沟了下,实在没有什么东东能把stata, wald test, matrix, symmetric联系在一起。
。。。。。。。。。。。。。。鄙人扶墙而出先。
PS: 发现有个笔算wald test的栗子,希望能给楼主丁点启发。
. ****** (B) TEST H0: b3 = 0, b4 = 0. . . * (1) Wald test requires estimation of unrestricted model only.
poisson y x2 x3 x4
Iteration 0: log likelihood = -238.77153
Iteration 1: log likelihood = -238.77153
Poisson regression Number of obs = 200
LR chi2(3) = 8.30 Prob > chi2 = 0.0401
Log likelihood = -238.77153 Pseudo R2 = 0.0171
------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
x2 | -.0275702 .0767909 -0.36 0.720 -.1780775 .1229371
x3 | .1630037 .0670848 2.43 0.015 .0315199 .2944874
x4 | .1026568 .0802139 1.28 0.201 -.0545595 .2598732
_cons | -.1653238 .0773479 -2.14 0.033 -.316923 -.0137246
------------------------------------------------------------------------------
.
.
* (1A) Stata Wald test command.
test (x3=0) (x4=0)
( 1) [y]x3 = 0 ( 2) [y]x4 = 0
chi2( 2) = 8.57 Prob > chi2 = 0.0138
.
.
* (1B) Wald test done manually.
* Use h'[RVR]-inv*h.
.
* Details below will change for each example.
.
* In particular, for nonlinear restrictions more work in forming R.
* Note that Stata puts the intercept last, not first.
.
* So here the second and third elements of b are set to zero.
. matrix bfull = e(b) /* 1xq row vector */
. matrix vfull = e(V) /* qxq matrix */
. matrix h = (bfull[1,2]\bfull[1,3]) /* hx1 vector */
. matrix R = (0,1,0,0\0,0,1,0) /* h x q matrix */
. matrix Wald = h'*syminv(R*vfull*R')*h /* scalar */
. matrix list hh[2,1]
c1
r1 .16300365
r2 .10265681
. matrix list
RR[2,4]
c1 c2 c3 c4
r1 0 1 0 0
r2 0 0 1 0
. matrix list
Wald symmetric
Wald[1,1]
c1
c1 8.5701855