[STATA] 随机过程-五种基本时间序列

标签:
stata随机过程基本时间序列白噪声随机游走非平稳序列教育 |
分类: STATA |
******** 随机过程-五种基本时间序列
*********
* by 莫家伟
* software:STATA 10.0
* 2011.3.25
* 【以下代码均可以直接复制到STATA新建的.do文件中,将需要执行的语句划选,
* 然后点击Do-File Editor工具栏最右边的“Do”按钮即可执行】
* 【准备知识】
* 平稳性定义
* “严平稳”:时间序列{x(t)}的联合概率分布不随时间而变,即任意n和k,x1 x2...
xn
*
与 x(1+k) x(2+k)...
x(n+k)的联合分布相同。
* “弱平稳”:即符合以下三条
*
(1)E(xt)= u , t=1,2,...
*
(2)Var(xt)=E(xt-u)^2=sigma,
t=1,2,...
*
(3)Cov(xt,x(t+k))=(E(xt-u)(x(t+k)-u)=rk , t=1,2,..., k!=0
*
即协方差不随选定的时间t而变化,只与间隔k有关。
* 开始模拟数据前的基本设置:
clear
set obs 500
gen t=_n
tsset t
gen x=0
* 1、white noise(白噪声过程,最基本的随机平稳时间序列)
gen noise=invnormal(uniform())
line noise t, title("1.白噪声过程") caption("Graphed by Daniel
MJWei")
file:///C:/Documents%20and%20Settings/daniel%20mo/Application%20Data/Tencent/Users/157125831/QQ/WinTemp/RichOle/5VT[W23%6$W(RJ~WMZ1$O[9.jpg随机过程-五种基本时间序列" TITLE="[STATA] 随机过程-五种基本时间序列" />
http://s15/bmiddle/74d7179749f50a5ef4b2e&690随机过程-五种基本时间序列" TITLE="[STATA] * 2、random walk(随机游走过程,最基本的非随机平稳时间序列)
drop noise x
gen noise=invnormal(uniform())
gen x=0 in 1
replace x=l.x + noise if t != 1
line x t, title("2.随机游走过程p>1") caption("Graphed
by Daniel MJWei")
drop noise x
gen noise=invnormal(uniform())
gen x=0 in 1
replace x=0.8*l.x + noise if t != 1
line x t, title("2.随机游走过程p<1") caption("Graphed
by Daniel MJWei")
drop noise x
gen noise=invnormal(uniform())
gen x=0 in 1
replace x=0 in 2
replace x=0 in 3
replace x=1.004*l.x - 1.05*l2.x + 1.003*l3.x + noise if t
> 3
http://s14/bmiddle/74d7179749f50b750265d&690随机过程-五种基本时间序列" TITLE="[STATA] 随机过程-五种基本时间序列" />
(P.S. 这个图不过重复几次随机过程,最后生成的都是这么美丽的形式,这或许就是所谓的偶然中的必然?)
(P.S. 这个图不过重复几次随机过程,最后生成的都是这么美丽的形式,这或许就是所谓的偶然中的必然?)
* 3、random walk with drift(带漂移项随机游走过程)
drop noise x
gen noise=invnormal(uniform())
gen x=0 in 1
replace x=0.1+ l.x + noise if t > 1
line x t, title("3.带漂移项随机游走过程") caption("Graphed by Daniel
MJWei")
* 4、trend stationary process(趋势平稳过程)
drop noise-x
gen noise=invnormal(uniform())
gen noise2=0 in 1
replace noise2=0.8*l.noise2 + noise if
t>1
gen x=1+ 0.1*t+ noise2
line x t, title("4.趋势平稳过程") caption("Graphed by Daniel
MJWei")
* 5、non-stationary process with deterministic
trend
drop noise-x
gen noise=invnormal(uniform())
gen x=0 in 1
replace x=0.1+ 0.01*t+ l.x + 10*noise if t > 1
line x t, title("5.确定性趋势非平稳过程") caption("Graphed by Daniel
MJWei")
dfuller x, trend
dfuller d.x, trend
******* 到此,五种基本的时间序列介绍完毕 *********
* 参考文献
* [1] 潘省初(2009).《计量经济学中级教程》. 清华大学出版社:p.146~148