考虑一个非常基本的估计命令,regress
。在 manual ,在方法和公式下,我们读到:
因此,根据手册,对于fweights
,Stata采用我的权重向量(用fw=
输入),并创建一个对角矩阵D
。现在,对角矩阵具有相同的转置。因此,我们可以定义D=C'C=C^2
,其中C
是一个矩阵,其中对角线中包含我的权重的平方根。
现在,给定我的符号和上面的文本,我们可以通过预乘X
和y
(以及 Z
)与矩阵C
。这样,(CX)'CX=X'C'CX=X'DX
,依此类推。在实践中,我们通过将每个变量乘以权重的平方根,逐个观察来实现这一点。
现在,我尝试手动复制 Stata 的估计,但得到了不同的结果。示例代码如下:
webuse auto, clear
keep if !mi(rep78)
qui regress price weight length [fw=rep78]
estimates store stata
preserve
replace price = price*sqrt(rep78)
replace weight = weight*sqrt(rep78)
replace length = length*sqrt(rep78)
qui regress price weight length
estimates store me
restore
estimates table stata me, b
输出:
----------------------------------------
Variable | stata me
-------------+--------------------------
weight | 4.1339379 1.7738167
length | -82.996394 16.502356
_cons | 9425.5443 -4071.7341
----------------------------------------
这场比赛很糟糕。如果我们将 fw=
更改为其他形式的权重,结果是相同的。有什么问题吗?我的数学或代码错误吗?如果不是,Stata 实际上是如何实现权重的?
最佳答案
发生这种不匹配是因为您忘记缩放截距/常数:
webuse auto, clear
keep if !mi(rep78)
qui regress price weight length [fw=rep78]
estimates store stata
preserve
replace price = price*sqrt(rep78)
replace weight = weight*sqrt(rep78)
replace length = length*sqrt(rep78)
gen constant = 1*sqrt(rep78)
qui regress price weight length constant, nocons
estimates store me
restore
estimates table stata me, b
这用加权版本的“伪截距”替换了通常的一列。
关于stata - Stata 如何实现权重?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52430106/