Question: Simultaneous first and second order autoccorelation

I can simulate first order autocorrelation as

restart;
with(Statistics);
randomize();
n := 1000;
p := 0.9;
r := Sample(RandomVariable(Normal(0, 1)), n);
for i from 2 to n do
x[1] := 0;
x[i] := p*x[i-1]+r[i] end do;
rr := [seq(x[i], i = 1 .. n)];
Correlation(rr[1 .. nops(rr)-1], rr[2 .. nops(rr)])

 

I can simulate second order autocorrelation as

restart;
with(Statistics);
randomize();
n := 1000;
p := 0.5;
r := Sample(RandomVariable(Normal(0, 1)), n);
for i from 3 to n do
x[1] := 0;
x[2] := 0;
x[i] := p*x[i-2]+r[i] end do;
rr := [seq(x[i], i = 1 .. n)];
Correlation(rr[1 .. nops(rr)-2], rr[3 .. nops(rr)])

 

But how do a simulate a variable that has both first order autocorrelation (p=0.9) and second order autoccorelation (p=0.5) simultaneously ??

Please Wait...