全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
18579 82
2013-02-12
刚才看到论文上某个帖子,汉森1999年内生门限变量的论文源代码要20个论坛币,这个实际汉森的个人网页上有,可以免费下载。这里贴一个上海师范大学商学院金融系朱敏老师改写的基于汉森1999年文献的源代码。汉森的代码基于面板数据,他把代码改写成为基于时间序列数据的代码。程序主要是用模拟数据生成了一个内含门限的序列,主要展示汉森方法在甄别内生门限值方面的优点。这个原创的改写程序对想要把该汉森的方法运用于非面板数据十分有用。
好东西不贵,支持原创,5个论坛币(主要用于下载超贵的论坛电子书),支持的顶起来~~~~~~


下面分析一下使用该源代码得到结果的含义:

本帖隐藏的内容

程序中生成y,x1和x2三个模拟序列。门限变量x1。x2基于x1当中的门限值分段,两个门限分别是1和2。
模拟数据生成的方程为:y=2*x1+2*I(x1<1)*x2+3*I(1<x1<2)*x2+4*I(x1>2)*x2,
生成之后,作为黑箱,x2的结构变化无法获得。


> summary(lm(y~x1+x2))
Call:lm(formula = y ~ x1 + x2)

Residuals:    Min      1Q  Median      3Q     Max
-3.4056 -0.9646 -0.0017  0.8606  3.5322
Coefficients:            Estimate Std. Error t value Pr(>|t|)   
(Intercept) -0.93267    0.09245  -10.09   <2e-16 ***
x1           2.09181    0.05966   35.06   <2e-16 ***
x2           4.06441    0.07519   54.06   <2e-16 ***
---Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.187 on 421 degrees of freedomMultiple R-squared: 0.9131,        
Adjusted R-squared: 0.9127 F-statistic:  2213 on 2 and 421 DF,  p-value: < 2.2e-16
这里,简单的回归无法甄别出x2发生结构变化的门限值。




> rhat1 <- model(0,trim_1,boot_1,0)
Threshold Estimate      1.951215
Confidence Region       1.829610 1.951215
Sum of Squared Errors   473.2038
Trimming Percentage     0.02
Thresholds 1.951215
Regime-independent Coefficients, standard errors, t value
2.09405  0.05321 39.35753
Regime-dependent Coefficients, standard errors, t value  
2.64070  0.06884 38.36143  
1.33142  0.08714 15.27978

R square 0.9306782
> rhat2 <- model(rhat1,trim_2,boot_2,2)
Fixed Thresholds        1.951215
Threshold Estimate      1.007903
Confidence Region       0.9930064 1.136067
Sum of Squared Errors   434.087
Trimming Percentage     0.02
Thresholds 1.951215 1.007903
Regime-independent Coefficients, standard errors, t value  
2.07755  0.05103 40.71259

Regime-dependent Coefficients, standard errors, t value  
2.09106  0.11104 18.83226  
1.88147  0.12231 15.38309  
0.84711  0.13770  6.15202
R square 0.9364086

> rhat1 <- model(rhat2,trim_2,0,1)
Fixed Thresholds        1.007903
Threshold Estimate      1.951215
Confidence Region       1.878330 2.05494
Sum of Squared Errors   434.087
Trimming Percentage     0.02
Thresholds 1.951215 1.007903
Regime-independent Coefficients, standard errors, t value  
2.07755  0.05103 40.71259
Regime-dependent Coefficients, standard errors, t value  
2.09106  0.11104 18.83226  
1.88147  0.12231 15.38309  
0.84711  0.13770  6.15202
R square 0.9364086
使用汉森的方法,可以找到两个门限值,保留两位小数为1.95, 1.01
,基于这两个门限值,我们可以求得真实的参数。

> new=cbind(y,x1,x2)

> new=as.data.frame(new)
> new$d1=0
> new$d2=0
> new$d1[new$x2<1.01]=1
> new$d2[new$x2>1.95]=1
> new$dx1=new$x2*new$d1
> new$dx2=new$x2*new$d2
> lm(y~x1+x2+dx1+dx2,data=new)
Call:lm(formula = y ~ x1 + x2 + dx1 + dx2, data = new)
Coefficients:
(Intercept)           x1           x2          dx1          dx2     
0.01304      2.08656      2.95714     -0.88684      1.02311  
> fit=lm(y~x1+x2+dx1+dx2,data=new)
> summary(fit)
Call:lm(formula = y ~ x1 + x2 + dx1 + dx2, data = new)
Residuals:    Min      1Q  Median      3Q     Max
-2.4375 -0.7173 -0.0049  0.6683  3.6269
Coefficients:            Estimate Std. Error t value Pr(>|t|)   
(Intercept)  0.01304    0.11580   0.113     0.91   
x1           2.08656    0.05139  40.599  < 2e-16 ***
x2           2.95714    0.11664  25.352  < 2e-16 ***
dx1         -0.88684    0.16469  -5.385 1.21e-07 ***
dx2          1.02311    0.10240   9.991  < 2e-16 ***
---Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.022 on 419 degrees of freedomMultiple R-squared: 0.9359,        
Adjusted R-squared: 0.9352 F-statistic:  1528 on 4 and 419 DF,  p-value: < 2.2e-16


> fit=lm(y~-1+x1+x2+dx1+dx2,data=new)

> fitCall:lm(formula = y ~ -1 + x1 + x2 + dx1 + dx2, data = new)
Coefficients:     x1       x2      dx1      dx2   
2.0862   2.9669  -0.8767   1.0186  


(x2<1|D1=1,D2=0)=2.090142
(1<x2<2|D1=0,D2=0)=2.9669  (x2<1|D1=0,D2=1)=3.985456  

最后方程为:y=2.0862*x1+2.090142*D1*x2+2.9669*D2*x2+3.985456*D3*x2

模拟生成的方程为:y=2*x1+2*D1*x2+3*D2*x2+4*D3*x2

可以看到利用内生门限模型,我们能够解析出原始模型。


附件列表

thresh_pnew.doc

大小:43 KB

只需: 5 个论坛币  马上下载

改写的源程序

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-2-12 21:58:04
谢谢楼主分享
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-2-12 23:44:49
好东西,感谢楼主
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-2-14 05:58:03
good things for R!!
thanks a lot!!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-2-14 13:47:11
3q3q3q
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-2-15 20:29:37
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群