楼主: rayallen8725
3453 3

[问答] Gauss中ADF test请教 [推广有奖]

  • 0关注
  • 0粉丝

已卖:12份资源

大专生

98%

还不是VIP/贵宾

-

威望
0
论坛币
3 个
通用积分
0.7500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
705 点
帖子
7
精华
0
在线时间
137 小时
注册时间
2011-3-19
最后登录
2024-10-28

楼主
rayallen8725 发表于 2012-8-11 22:09:21 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
请教如何使用GAUSS编程做出单位根检验里的ADF test. 从最大lag为10开始test down,请教各位怎么能编出这个procedure出来。
二维码

扫码加我 拉你入群

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

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

关键词:GAUSS test ADF Aus USS test

沙发
xuelida 在职认证  发表于 2012-8-18 12:20:43
new;cls;
maxk = 8;  @数据选择滞后值的设置的最大滞后@
n = 100;
crit_t = 1.645;
p = 1;       @ 1 = with trend, 0 = with constant only, -1 = no constant or trend @
select = 0;  @ 1 = fixed lag, 0 = data dependent lag selection @
y = cumsumc(rndn(n,1));  @生成y序列@
@ or, Read the dat file here. load data[n,1] = data.txt;  @

/* Using a Fixed lag */
if select == 1;
   lag = 4;
   {beta,tval, alpha, tstat} = adf(y,p,lag);   @调用ADF估计程序@
   format /rd/m1 12,4;
   "Using a Fixed lag"
   "Fixed lag    = " lag;
   "T(a-1)       = " alpha;
   "ADF stat     = " tstat;
   "Estimated coefficients :
     (x(t-1), dx(t-1), dx(t-2), ... dx(t-k), const, trend) ";
   beta';
   "t-stat";
   tval';
   goto next;
endif;

/* Using data-driven lag selection procedure */
statkeep = zeros(maxk+1,1);
tvalkeep = zeros(maxk,1);

{beta,tval, alpha, tstat} = adf(y,p,0);
statkeep[1] = tval[1];
j=1;
do while j <= maxk;    @构造数据选择滞后值的一个循环@
   {beta,tval, alpha, tstat} = adf(y,p,j);
   statkeep[j+1] = tval[1];   /* statkeep  for k = 0, 1, 2, ..., maxk */
   tvalkeep[j] = tval[j+1];   /* tvalkeep  for k = 1, 2, ..., maxk */
j = j + 1;
endo;

@ selection using t-test,这个可以看作者的文章,通过abs(tvalkeep[j]) > crit_t来选择@
/* select the lag where the coeff is sig. from maxk to 0. if all coeff are insig., kk = 0  */
j = maxk;
do while j >= 0;
        if (abs(tvalkeep[j]) > crit_t) or (j == 0);
            kk = j;
            j = 0;
        endif;
j = j - 1;
endo;

@ kk = selected lag @
{beta, tval, alpha, tstat} = adf(y,p,kk);
   format /rd/m1 12,4;
   "Using Data dependent selection of the lag";
   "Selected lag = " kk;
   "T(a-1)       = " alpha;
   "ADF stat     = " tstat;
   "Estimated coefficients :
     (x(t-1), dx(t-1), dx(t-2), ... dx(t-k), const, trend) ";
   beta';
   "t-stat";
   tval';
next:
end;

/*** ADF
** Format:  {beta, tval, alpha, tstat} = adf(x,p,l);
** Input:   x     -- time series variable
**          p     -- order of the time-polynomial to include in the
**                   ADF regression.  Set p = -1 for no deterministic
**                   part.
**          l     -- number of lagged changes of x to include in the
**                   fitted regression.
** Output:  alpha       --  estimate of the autoregressive parameter;
**          tstat       --  ADF t-statistic
**          beta        --  coeff. of (x(t-1), dx(t-1), dx(t-2), ... dx(t-k),
                                   constant, time trend)
**          tval        --  t-values
*/
proc (4) = adf(x,p,l) ;
local b,k,z,res,so,var_cov,xx, tval;
local timep,t,m,xmat,nobs,dep,ch,f;
     if (p < -1);
        "Error: p cannot be set < -1";
         retp(0,0,zeros(6,1));
     endif ;
     if (cols(x) > 1);
        "Error: ADF cannot handle a data matrix; cols(x) > 1 (=" cols(x) ")";
         retp(0,0,zeros(6,1));
     endif ;

     nobs    = rows(x);
     if (nobs - (2*l) + 1 < 1) ;
        "Error: l is too large; negative degrees of freedom.";
         retp(0,0,zeros(6,1));
     endif ;

     dep     = trimr(x,1,0);
     ch      = diff(x,1);
     k       = 0     ;
     z       = trimr(lagn(x,1),1,0) ;
     If (l > 0) ;
        do until k >= l ;
           k = k + 1 ;
           z = z~lagn(ch,k) ;
        endo ;
     Endif ;
     z       = trimr(z,k,0);
     dep     = trimr(dep,k,0);
     if ( p > -1) ;
        z = z~ptrend(p,rows(z));
     endif ;
     b       = dep/z ;
     res     = dep - z*b ;
     so      = (res'res)/(rows(dep)-cols(z));
     var_cov = so*inv(z'z);
     b[1,1] = b[1,1] - 1;
     tval    = b ./ sqrt(diag(var_cov));
retp(b,tval,b[1,1],(b[1,1])/sqrt(var_cov[1,1])) ;
endp ;

proc lagn(x,n);
    local y;
    y = shiftr(x', n, (miss(0, 0))');
    retp(y');
endp;

proc diff(x,k) ;
     if ( k == 0) ;
        retp(x) ;
     endif ;
     retp(trimr(x,k,0)-trimr(lagn(x,k),k,0)) ;
endp ;
已有 1 人评分经验 论坛币 学术水平 热心指数 收起 理由
xuehe + 20 + 40 + 5 + 1 根据规定进行奖励

总评分: 经验 + 20  论坛币 + 40  学术水平 + 5  热心指数 + 1   查看全部评分

藤椅
rayallen8725 发表于 2012-9-6 19:36:33
xuelida 发表于 2012-8-18 12:20
new;cls;
maxk = 8;  @数据选择滞后值的设置的最大滞后@
n = 100;
zhe shi wang shang de ,dan shi shi cuo de

板凳
太极无极 在职认证  发表于 2013-3-6 06:29:38
运行程序,GAUSS 提示,undefined symobls
ptrend        d:\gauss9.0\adftest.g(112)

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 18:06