Just wondering if anyone would like to help me with this.
I'd like to obtain 1000 samples each of 100 observations of the following autoregressive equation
x(t+1) = a*x(t) + e(t+1)
where x is some random variable and e is white noise. To do it once, you can write a for loop as follows:
x(1) = 0
for t = 1:100
x(t+1)=a*x(t) + e(t+1)
That's fine. But how would I repeat the process 1000 times, each time with a different 100 observation sample for e and also have the x series from each sample stored?
Ron - Thank you very much for this.
May I complicate it slightly?
If x were now a vector of variables and e a vector of shocks assumed to be multivariate normal and correlated with each other, how would you obtain the 1000 samples each of 100 observations?
RonLCode:nt=100; nx=4; nreps=1000 sigma=[1, 0.1; 0.1, 1]; x=zeros(nt,nx,nreps); for t = 1:nt x(t+1,:,:)=a*x(t,:,:) + noise(4,1000,sigma); end