/* AR(p) */ new; cls; psi={0.8,-0.1,0.1}; s2=0.1; n=1000; x=arsim(psi,s2,n); library pgraph; graphset; title("AR(p)"); t=seqa(1,1,n); xy(t,x); proc arsim(psi,s2,n); local cutn,p,e,x,t; cutn=100; /* first some data to cut off */ p=rows(psi); print/lz "p=" rows(psi); e=rndn(cutn+n,1)*sqrt(s2); x=zeros(cutn+n,1); t=p+1; do while t<=cutn+n; x[t]=rev(psi)'x[t-p:t-1]+e[t]; t=t+1; endo; x=x[cutn+1:cutn+n]; retp(x); endp;