【发布时间】:2020-10-03 12:20:06
【问题描述】:
我需要帮助进行假设检验来比较我在 Stata 中的两个解释变量的系数。我的 null 和替代方法是:
null:β1=β2 vs alt:β1>β2。
到目前为止,我已经使用命令test 来比较两个估计值。但是,我不知道我是否可以修改 test 以适应我的 alt。
【问题讨论】:
标签: statistics stata hypothesis-test
我需要帮助进行假设检验来比较我在 Stata 中的两个解释变量的系数。我的 null 和替代方法是:
null:β1=β2 vs alt:β1>β2。
到目前为止,我已经使用命令test 来比较两个估计值。但是,我不知道我是否可以修改 test 以适应我的 alt。
【问题讨论】:
标签: statistics stata hypothesis-test
要对系数进行单边检验,您可以
如果您正在测试系数的差异(因为 a=b 等效于 a-b=0),则该方法与进行单个系数相同。您需要对差异进行双向测试:
sysuse auto, clear
regress price mpg weight
gen high_mpg = mpg>20
gen high_weight = weight>3000
reg price high_mpg high_weight foreign
/* Test H0: diff = 0 */
test high_weight - foreign = 0
display r(p)
display r(F)
/* The ttail approach works when the actual coefficient difference is positive or negative */
local sign_diff = sign(_b[high_weight] - _b[foreign] - 0)
display "p-value for Ha: diff < 10 = " ttail(r(df_r),`sign_diff'*sqrt(r(F)))
display "p-value for Ha: diff > 10 = " 1-ttail(r(df_r),`sign_diff'*sqrt(r(F)))
/* Can also do it by hand like this if diff is positive (like above) */
display "p-value for Ha: diff < 0 = " r(p)/2
display "p-value for Ha: diff > 0 = " 1-r(p)/2
/* if difference is negative, you can still do it by hand */
/* but need to flip the p-value division rules since we are on the other */
/* side of the distribution */
/* Test H0': diff2 = -400 */
test high_mpg - foreign = -400
local sign_diff2 = sign(_b[high_mpg] - _b[foreign] + 400)
display "p-value for Ha': diff2 < 0 = " ttail(r(df_r),`sign_diff2'*sqrt(r(F)))
display 1-r(p)/2
display "p-value for Ha': diff2 > 0 = " 1-ttail(r(df_r),`sign_diff2'*sqrt(r(F)))
display r(p)/2
如果您的测试返回 r(chi2) 而不是 r(F),则需要将 ttail 部分换成
normal(`sign_diff'*sqrt(r(chi2)))
【讨论】:
ttail 部分换成 -normal(`sign_diff'*sqrt(r(chi2)))-。