stata - Stata 如何实现权重?

标签 stata

考虑一个非常基本的估计命令,regress。在 manual ,在方法和公式下,我们读到:

enter image description here

因此,根据手册,对于fweights,Stata采用我的权重向量(用fw=输入),并创建一个对角矩阵D 。现在,对角矩阵具有相同的转置。因此,我们可以定义D=C'C=C^2,其中C是一个矩阵,其中对角线中包含我的权重的平方根。

现在,给定我的符号和上面的文本,我们可以通过预乘Xy(以及 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/

相关文章:

stata - Stata 中类内相关系数 (ICC) 的引导

stata - 根据最近的 I/观察生成变量

在 R 中复制 Stata 边距

r - 如何将Stata marksample转换为R语言?

stata - Stata 中的综合歧视指数 (IDI)

Stata:向 estout 添加系数

loops - 使用 Stata 中变量的唯一观测值创建向量

python - 具有大型 .dta 文件的 Pandas read_stata()

使用非默认选项运行现有函数

ruby - Heroku Rails 应用程序的数据挖掘/统计分析选项?