请选择 进入手机版 | 继续访问电脑版
楼主: zhaomn200145
13325 27

[推荐]单一时间序列门限协整的GAUSS程序 [推广有奖]

zhangtao 发表于 2011-8-1 14:16:06 |显示全部楼层 |坛友微信交流群
epoh 发表于 2011-8-1 10:43
这的确是一般的时间序列
data(zeroyld)
zeroyld
epoh老师,您好!
加上library pgraph; 后程序可以运行,太好了!我想问一下:您是怎么看出需要加library pgraph; 这一行呢?
另外,您说的Rcode 和matlab code我没有找到,您能上传一份,我学习学习好吗?
非常感谢!
数学好就是要天天学

使用道具

epoh 发表于 2011-8-1 18:34:43 |显示全部楼层 |坛友微信交流群

zhangtao兄,有时间的话

可以看一下GAUSS library file

lib\pgraph.lcg

就可看到里面定义了

一些你写出的变量

pgraph.src
   graphset  
   pqgwin  
   fonts
   title
   ylabel
   xlabel

pxy.src
   xy

###############
Bruce E. Hansen
Programs -- Threshold Models
Gauss code,Rcode,Matlab code

  http://www.ssc.wisc.edu/~bhansen/progs/progs_threshold.html

ps:
two-regime threshold cointegration.....

Rcode由于R版本的更新

plot 有些问题,需要修改.

要做这个模型,

我建议用 R package ("tsDyn")

TVECM.HStest()  Test of linear cointegration vs threshold cointegration
               Tests the null of linear cointegration against threshold cointegration
               following Hansen and Seo (2002).
               Fixed regressor anfd residual bootstrap are available.

TVECM.SeoTest()  No cointegration vs threshold cointegration test
                 Test the null of no cointegration against threshold cointegration
                 with bootstrap distribution of Seo(2006)

TVECM()         Treshold Vector Error Correction model (VECM)
                Estimate a Treshold Vector Error Correction model (VECM)

data(zeroyld)
data<-zeroyld
##Estimate a TVECM (we use here minimal grid, it should be usually much bigger!)
tv<-TVECM(data, nthresh=2,lag=1, ngridBeta=20, ngridTh=30, plot=TRUE,trim=0.05, common="All")

已有 2 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 非常感谢epoh大师!
ywh19860616 + 5 + 5 + 5 资料非常好

总评分: 学术水平 + 10  热心指数 + 10  信用等级 + 10   查看全部评分

使用道具

jiezichen 发表于 2011-11-1 11:11:57 |显示全部楼层 |坛友微信交流群
epoh 发表于 2011-8-1 18:34
zhangtao兄,有时间的话可以看一下GAUSS library file lib\pgraph.lcg就可看到里面定义了一些你写出的变量pg ...
太感谢牛人们的分享了 感谢

使用道具

waveland 发表于 2012-6-8 08:28:52 |显示全部楼层 |坛友微信交流群
/*
**        This procedure performs Tsay's (1998) multivariate
**        TAR specification test
**        and was written by Ming Chien Lo on August 27, 1999.
**
**        Last updated: August 28, 1999.
**
**        Input:        y        T x k endogenous data series
**                        x        T x q exogenous data series
**                        z        T x 1 threshold data series
**                        p        order of the autoregressive process for y
**                        q        order of the autoregressive process for x
**                        d        lag index for threshold variable z{t-d}
**                        m0        starting value for the resursive regression
**
**        Output:        Cd        resulting LR-statistics
**
*/

proc tsaymul(y,x,z,p,q,d,m0);
local h, t, k, v, nr, ztd, yt, ytl, i, yl, kk, xtl, vv, xt, gs, y_, x_, Vm, phim, phim1, etham1,
        ym1, xm1, Km1, x1, psi, w, Cd, S0, S1, xl, em1, invXX;

h=maxc(p|q|d);                @ starting index of the arranged data set @
t=rows(y);                        @ total no. of observations @
k=cols(y);
v=cols(x);
nr=p*k+q*v+1;                @ no. of RHS regressors @

ztd=z[h+1-d:t-d];        @ potential threshold @
yt=y[h+1:t,.];                @ truncated y series @

ytl=zeros(rows(y),p*k);        @ form and do the same thing for y{t-p} matrix @
i=1;
do until i>k;
        yl=shiftr(y[.,i]',seqa(1,1,p),0);
        kk=(i-1)*p+1;
        ytl[.,kk:kk+p-1]=zeros(p,p)|trimr(yl',p,0);
i=i+1;
endo;
ytl=ytl[h+1:t,.];
xt=ytl;

if x NE 0;
        xtl=zeros(rows(x),q*v);        @ form and do the same thing for x{t-q} matrix @
        i=1;
        do until i>v;
                xl=shiftr(x[.,i]',seqa(1,1,q),0);
                vv=(i-1)*q+1;
                xtl[.,vv:vv+q-1]=zeros(q,q)|trimr(xl',q,0);
        i=i+1;
        endo;
        xtl=xtl[h+1:t,.];
        xt=ytl~xtl;                @ truncated independent variable matrix @
endif;

gs=sortind(ztd);                @ index for sorted z{t-d} @
y=yt[gs,.];                        @ arranged Y according to sorted y{t-d} @
x=xt[gs,.];                        @ arranged X according to sorted y{t-d} @
x=ones(t-h,1)~x;

@ derive first phi_m for the first m cases according to m0 @
etham1=zeros(k,t-h-m0);
y_=y[1:m0,.];
x_=x[1:m0,.];
Vm=invpd(moment(x_,0));
phim=Vm*x_'y_;

@ recursive regression @
i=1;
do until i>t-h-m0;

        ym1=y[m0+i,.]';        @ yt(m+1)+d @
        xm1=x[m0+i,.]';        @ xt(m+1)+d @

        @ compute predictive error @
        em1=ym1-phim'xm1;
        etham1[.,i]=em1/sqrt(1+xm1'Vm*xm1);

        @ recursion @
        Km1=Vm*xm1/(1+xm1'*Vm*xm1);
        phim1=phim+Km1*em1';       
        x_=x[1:m0+i,.];
        Vm=invpd(moment(x_,0));        @ Vm for next loop @

        phim=phim1;

i=i+1;
endo;

@ calculate F-statistics @
x1=x[m0+1:t-h,.];
invXX=invpd(moment(x1,0));
psi=invXX*x1'etham1';
w=etham1'-x1*psi;
w=w';
S0=(1/(t-h-m0))*(etham1*etham1');
S1=(1/(t-h-m0))*(w*w');
Cd=(t-h-m0-nr)*(ln(det(S0))-ln(det(S1)));

retp(Cd);
endp;

使用道具

843978571 发表于 2014-3-12 09:57:50 |显示全部楼层 |坛友微信交流群
epoh 发表于 2011-8-1 10:43
这的确是一般的时间序列
data(zeroyld)
zeroyld
老师您好, H-S的程序只给出了二元的情况,如果要做多维的怎么办?我自己通过数组的方式修改了格点搜索法,可以估计出三维参数情况,但是Boostrap 后面的程序不知道怎么去改了。

使用道具

chensi26 发表于 2015-1-31 15:29:56 |显示全部楼层 |坛友微信交流群
dieme 发表于 2009-7-13 19:19
各位看一下

另外,
你好,请问你最后做这个时序的门限模型,是把面板程序设定为1来做的吗?结果如何,可行否?多谢

使用道具

cug107071 发表于 2017-1-16 17:17:51 |显示全部楼层 |坛友微信交流群
epoh 发表于 2011-8-1 18:34
zhangtao兄,有时间的话可以看一下GAUSS library file lib\pgraph.lcg就可看到里面定义了一些你写出的变量pg ...
请问,我是否可以把TVECM.HStest() 和TVECM.SeoTest()理解为分别针对VECM和残差的门限协整检验呢

使用道具

ydc129 发表于 2017-3-6 23:22:30 |显示全部楼层 |坛友微信交流群
谢谢分享

使用道具

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

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 17:12