% % Economics 303: % Simulation of AR(1) process for lecture 1 % % George J Hall % Brandeis University % August 2006 % close all clear % % initalize the x series % T = 100 x = zeros(T,1); % % % for t = 1:(T-1) x(t+1) = 0.95*x(t) + (round(rand)-0.5); end figure(1) plot((1:T),x); xlabel('time'); ylabel('x(t)'); title('AR(1) Simulation'); disp('i am pausing, hit the enter key to continue'); pause % % initalize the two more series % y = zeros(T,1); z = zeros(T,1); for t = 1:(T-1) y(t+1) = 0.95*y(t) + (round(rand)-0.5); z(t+1) = 0.95*z(t) + (round(rand)-0.5); end figure(2) plot((1:T),x,(1:T),y,'r',(1:T),z,'g'); xlabel('time'); ylabel('three simulated series'); title('AR(1) Simulation');