查看原文
其他

跨数据比较回归系数技巧

计量经济圈 计量经济圈 2019-06-30

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

箱:econometrics666@sina.cn

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

跨数据比较回归系数之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 at https://stats.idre.ucla.edu/stat/stata/faq/compreg3.htm shows how you can compare regression coefficients across three groups using xi and by forming interactions.  This can also be done using suest as 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


跨数据比较回归系数之Binary Choice(Logit and Probit):

参考文献:

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)


* 计算delta Compute 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)


* 计算delta  Compute delta

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


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

lrtest step3 step4c, stats

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


写在后面:各位圈友,咱们的计量经济圈社群里面资料和计量咨询都很多,希望大家能够积极加入咱们这个大家庭戳这里)。我们已经邀请社群里的圈友建立了微信群与圈圈对话,进去之后一定要看“群公告”,不然接收不了群息。


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


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



    您可能也对以下帖子感兴趣

    文章有问题?点此查看未经处理的缓存