Simulating multiple AR(1) series

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
basher
Posts: 14
Joined: Tue Mar 08, 2011 6:11 am

Simulating multiple AR(1) series

Unread post by basher »

Hello,

I am trying to replicate a paper results, where I want to generate multiple (say, 10) AR(1) processes with AR(1) parameters randomly drawn from the [0.48,0.83] interval, and disturbances drawn from a zero-mean normal distribution where the standard deviation was randomly selected from the [0.005,0.014] interval. I have been trying to play with the following code without any success:

*--------------- begin --------------
seed 2011
all 100
set y = 0
com alpha = %uniform(.48,.83)
com sd = %uniform(.005,.014)
set et = %ran(sd)
do i = 1,10
set y(i) 2 100 = alpha*y{1}+et
end do i
*--------------- end --------------

Definitely I am missing something here. Your help will be highly appreciated. Thank you.

Basher
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Simulating multiple AR(1) series

Unread post by TomDoan »

This will generate 10 series using a single draw for the alpha and sd. If you also want to vary those with the draws, just move the two compute instructions inside the loop rather than leaving them outside.

Code: Select all

seed 2011
all 100
dec vect[series] y(10)
com alpha = %uniform(.48,.83)
com sd = %uniform(.005,.014)
set et = %ran(sd)
do i = 1,10
   set(first=0.0) y(i) 1 100 = alpha*y(i){1}+et
end do i
basher
Posts: 14
Joined: Tue Mar 08, 2011 6:11 am

Re: Simulating multiple AR(1) series

Unread post by basher »

Thank you Tom. I moved the two compute instructions inside the loop:
*--------------- begin --------------
seed 2011
all 100
dec vect[series] y(10)
do i = 1,10
com alpha = %uniform(.48,.83)
com sd = %uniform(.005,.014)
set et = %ran(sd)
set(first=0.0) y(i) 1 100 = alpha*y(i){1}+et
end do i
*--------------- end --------------
It is working fine. I wanted to create two variables x1 and x2, where x1 is a random series from the vector y(10) created above and x2 is the median of the 10 AR(1) series created above. I couldn't find an appropriate syntax for calling a series from a vector. Thank you once again.
Post Reply