跨数据比较回归系数技巧

欢迎投稿(荐稿)计量经济圈,计量相关都行

注:文章来自计量经济圈社群圈友投稿,欢迎各路计量爱好者赐稿。

跨数据比较回归系数之OLS:

https://stats.idre.ucla.edu/stata/code/comparing-regression-coefficients-across-groups-using-suest/

Comparing Regression Coefficients Across Groups using Suest | Stata Code Fragments

The FAQ athttps://stats.idre.ucla.edu/stat/stata/faq/compreg3.htmshows how you can compare regression coefficients across three groups usingxiand by forming interactions. This can also be done usingsuestas shown below.(这里的链接给了用哑变量交互项来比较不同数据的回归系数的方法,下面的方法用suest命令来实现。)

*从互联网读入数据

use https://stats.idre.ucla.edu/stat/stata/faq/compreg3

*用年龄为1的数据组进行回归

regress weight height if age==1

*存储第一组回归的结果到age1中

est store age1

*用年龄为2的数据组进行回归

regress weight height if age==2

*存储第一组回归的结果到age2中

est store age2

*用年龄为3的数据组进行回归

regress weight height if age==3

*存储第一组回归的结果到age3中

est store age3

*利用suest进行这三个模型的同时估计

suest age1 age2 age3

*利用test检验不同模型的beta是否相等

test [age1_mean]height=[age2_mean]height

( 1) [age1_mean]height - [age2_mean]height = 0

chi2( 1) = 24.04

Prob > chi2 = 0.0000

*利用test检验不同模型的beta是否相等,多个模型可以用accum参数

test [age2_mean]height=[age3_mean]height, accum

跨数据比较回归系数之BinaryChoice(LogitandProbit):

参考文献:

Williams R. Using Heterogenous Choice Models to Compare Logit and Probit Coefficients Across Groups[J]. Sociological Methods & Research, 2009, 37(4):531-559.

*首先安装oglm的第三方程序

ssc install oglm

Appendix: Stata Code

The following code replicates parts of the analysis in this paper. The user-written oglm and mfx2 commands must be installed; from within Stata type help findit. For more information, see the author‟s web page at http://www.nd.edu/~rwilliam/oglm/index.html.

Stata Code for Tables 1 & 2:

* Step 1.无约束模型,所有的回归系数可以随性别而改变Unconstrained models, all coefficients can differ by gender.

use "http://www.indiana.edu/~jslsoc/stata/spex_data/tenure01.dta", clear

* Allison(原文作者)将样本限制在前10年会获得终身教职的Allison limited the sample to the first 10 years untenured

keep if pdasample

*选择男性样本进行模型估计Males Only

oglm tenure year yearsq select articles prestige if male, store(step1male)

*选择女性样本进行模型估计Females Only

oglm tenure year yearsq select articles prestige if female, store(step1fem)

*采用了交互项的等价的混合模型Equivalent pooled model, using interactions.

oglm tenure year yearsq select articles prestige f_year f_yearsq f_select f_articles f_prestige female, store(step1)

* Step 2.混合模型,只有截距项因性别而改变Pooled model; only the intercepts differ by gender.

* Allison提到了该模型但并未在文中汇报Allison refers to this model but does not present it in the paper.

oglm tenure year yearsq select articles prestige female, store(step2)

* Step 3.残差方差允许根据性别而改变Residual variances allowed to differ by gender.

* Allison的模型实际上是异质选择模型的一个特例,用oglm包可以很方便的计算delta

* Allison’s model is actually a special case of a heterogeneous choice model,

*and it is easy to compute Allison’s delta using oglm.

*与Allison文章中的表2的结果进行对比Compare these results with the first half of Allison’s Table 2.

oglm tenure female year yearsq select articles prestige , het(female) store(step3)

*计算deltaCompute delta

display (1 - exp(.3022305))/ exp(.3022305)

* Step 4A.检验残差方差不同时alphas是否相等Test that the Alphas are = but residual variances differ.

lrtest step2 step3, stats

* Step 4B.检验跨组的alpha在残差方差不同时alpha是否相等

* Test whether any Alphas differ across groups given that residual variances differ.

lrtest step1 step3, stats

* Step 4C.检验文章的效果是否存在组间差异Test whether the effect of articles differs across groups.

*首先需要估计带交互项的模型First have to estimate the model with the interaction term added.

*与Allison文章中的表2结果进行对比Compare this with the second half of Allison’s Table 2.

oglm tenure female year yearsq select articles prestige f_articles, het(female) store(step4c)

*计算deltaCompute delta

display (1 - exp(.1774193))/ exp(.1774193)

*现在进行female*articles交互项的检验Now do the formal test of the female*articles interaction term.

lrtest step3 step4c, stats

给推文作者赞赏,我们会全部移交于他,如果你觉得推文作者辛苦或者用心,那就在文后给该作者打赏吧。欢迎你加入计量经济圈社群,一起探讨前沿计量理论和实证方法。

帮点击一下下面的小广告,谢谢支持!

社群圈友可以进入,非社群圈友需要先加入社群后再进入

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180410A00VSO00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。

扫码关注云+社区

领取腾讯云代金券