全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Gauss专版
9737 38
2012-03-15
Gauss 编程应用于学科前沿一:单位根
单位根理论我就不说了,虽然已经有30余年的历史了,发展也很成熟,但做实证特别是时间序列和长序列面板数据模型时,还需要用到单位根检验。
因此,本帖子从最初的单位根检验开始,到非线性单位根检验,再到面板数据单位根,我们希望通过本帖,基本上掌握单位根检验的各种程序。

在code里,我们有带实际数据的,也有模拟数据,当然也可能只有调用程序,都能用。

我们先从DF检验开始:
1、这个例子是DF检验的模拟,重复10000次,并计算临界值,注意临界值是在原假设下估计的,也就是先生成带单位根的数据AR,即proc gen_ar1(phi0,e_mat); AR程序你也可以自己编,不像这样。

/* Dickey Fuller Distribution */
   new;cls;
   library pgraph;
   tru_phi=1;
   H0_phi=1;
   n_ob =100;
   n_trial =10000;
   t_mat=zeros(n_trial,1);
trial=1;
do until trial > n_trial;
   trial;;"th Iteration";
   e=rndn(n_ob,1);
   y=gen_ar1(tru_phi,e);
   Yt = y[2:n_ob,1];  
    Ylag=y[1:n_ob-1,1];

   tt=rows(Yt);
  X=Ylag~ones(tt,1)~seqa(1,1,tt) ;
   b=inv(X'X)* X'Yt;
   residual=Yt-X*b;
   sigma2=residual'residual/(tt-cols(x));
   vc_b = sigma2 * inv(X'X);   @Variance-Covariance matrix of b@
   se_b =sqrt(vc_b[1,1]);  @Standard error of b@
   t_value=(b[1,1]-H0_phi)/se_b;  @test statistic for H0: phi= H0_phi@
   t_mat[trial,1]=t_value;
trial=trial +1;
endo;
sorted_t = sortc(t_mat,1);
output file =dky_flr.out reset;
    "5% Critical Value is:" sorted_t[500,1];
output off;
{a,b,c}= histp(t_mat,50);
end;
@======================================@
proc gen_ar1(phi0,e_mat);
     local x0_mat,i;
     x0_mat = zeros(n_ob,1);
     x0_mat[1,1]=e_mat[1,1];
     i=2;
     do until i>n_ob;
         x0_mat[i,1]=phi0*x0_mat[i-1,1] + e_mat[i,1];
     i=i+1;
     endo;
retp(x0_mat);
endp;





二维码

扫码加我 拉你入群

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

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

全部回复
2012-3-15 22:08:34
再看一例,上面的解释变量带常数项和趋势项,
下面我们不考虑这些。
/*========= ============================
Test statistics = sqrt(T)*(phi_hat - H0_phi)
DGP : Y(t) =phi*Y(t-1) + Et,    phi=0
Reg : Y(t) =b1*Y(t-1) +Et
=======================================*/
new;cls;
library pgraph;  @调用图函数库@
   tru_phi=0;
   H0_phi=0;
   n_ob =100;
   n_trial =1000;
   count=0;
   t_mat=zeros(n_trial,1);

ii=1;
do until ii> n_trial;
     trial;;"th Iteration";
@============= DGP =============@
     ymat = zeros(n_ob,1);
     ymat[1]=rndn(1,1)*sqrt((1/(1-tru_phi^2)));
     i=2;
     do until i>n_ob;
         ymat[i,1]=tru_phi*ymat[i-1,1] + rndn(1,1);
     i=i+1;
     endo;
@===========回归==============@
   Yt = ymat[2:n_ob,1];  
   Ylag=ymat[1:n_ob-1,1];
   X=Ylag;

   b=inv(X'X)* X'Yt;

@==========Test Statistic==========@
   static=sqrt(n_ob)*(b-H0_phi);                @test statistic for H0: phi= H0_phi@
   t_mat[ii,1]=static;
@====Counting the # of rejction H0===@
   if abs(static) > 1.96;  @Critical value at a 5% significance level@
       count=count+1;           
   endif;
ii=ii +1;
endo;

output file = dky_flr.prn reset; t_mat; output off;
{a,b,c}= histp(t_mat,50);   @直方图@
output file = dky_flr.out reset;
"Number of rejections from conventional t-test ";   count;
output off;
end;
二维码

扫码加我 拉你入群

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

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

2012-3-15 22:10:34
如果回归方程带常数项 : Y(t) =b0+b1*Y(t-1) +Et

则把上面程序中的x换为:X=ones(n_ob-1,1)~Ylag;就可以了
二维码

扫码加我 拉你入群

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

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

2012-3-15 22:16:49
上面两例如果大家注意观看图型,我们会发现基本上是正态分布,因为我们设置了tru_phi=0;
下面我使用不同的统计量,使用tru_phi=1; 该统计量是偏态,也就是说当有单位根了,传统的渐近分布就不能用了。
读者可以看陆懋祖的高等计量经济学,有关单位根的渐近分布推导。

/*========= ============================
检验统计量不是根据t统计量计算的,现在是: T*(phi_hat - H0_phi)
DGP : Y(t) =phi*Y(t-1) + Et,  phi=1
Reg : Y(t) =b1*Y(t-1) +Et
=======================================*/
new;cls;
library pgraph;
   tru_phi=1;
   H0_phi=1;
   n_ob =100;
   n_trial =1000;
   count=0;
   t_mat=zeros(n_trial,1);

trial=1;
do until trial > n_trial;
   trial;;"th Iteration";
@============= DGP =============@
     ymat = zeros(n_ob,1);
     i=2;
     do until i>n_ob;
         ymat[i,1]=tru_phi*ymat[i-1,1] + rndn(1,1);
     i=i+1;
     endo;
@=============Reg==============@
   Yt = ymat[2:n_ob,1];  Ylag=ymat[1:n_ob-1,1];
   X=Ylag;
   b=inv(X'X)* X'Yt;

@==========Test Statistic==========@
   static=(n_ob)*(b-H0_phi);  @test statistic for H0: phi= H0_phi@
   t_mat[trial,1]=static;
@====Counting the # of rejction H0===@
   if static < -8;    @Testing the hypothesis at a 5% significance
                                   level = -8 for case 1 @
        count=count+1;
   endif;

trial=trial +1;
endo;

{a,b,c}= histp(t_mat,50);
output file = dky_flr.out reset;

"Number of rejections from conventional t-test ";   count;
output off;
end;

二维码

扫码加我 拉你入群

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

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

2012-3-15 22:19:59
读者最好根据例一中的临界值程序得到相关的临界值,然后在对后面例子中的
1.96进行替代,这样就更精确了,比如你的数据是40个,这个时候可以模拟得到40个数据的临界值,虽然相差不大,但很有用。
   if abs(static) > 1.96;        @Testing the hypothesis at a 5% significance
                                   level@
        count=count+1;
   endif;
二维码

扫码加我 拉你入群

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

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

2012-3-15 22:21:07
明天继续,希望用1个月的时间把单位根相关问题都整理处理。
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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