/* This program graphs the ACF and PACF for an MA(2) process. Theta1 is the first-order moving average coefficient. Theta2 is the second-order moving average coefficients. For invertibility the moving average coefficients must satisfy the following inequalities: theta1 + theta2 < 1, theta2 - theta1 < 1, and |theta2| < 1. */ data a; array r{30}; array q(30,30); theta1=1.4; /*you can input the values of two coefficients here*/ theta2=-0.6; do lag = 1 to 30; if lag=1 then r{lag}=(-theta1+theta1*theta2)/(1+theta1**2+theta2**2); else if lag=2 then r{lag}=-theta2/(1+theta1**2+theta2**2); else r{lag}=0; rho=r{lag}; do j= lag to 1 by -1; if lag=1 then q(1,1)=r{lag}; else; do; sum1=0; sum2=0; do i=1 to lag-1; subsum1=q(lag-1,i)*r(lag-i); sum1=sum1+subsum1; subsum2=q(lag-1,i)*r(i); sum2=sum2+subsum2; end; if lag=j then do; q(lag,j)=(r(lag)-sum1)/(1-sum2); phijj=q(lag,j); end; else q(lag,j)=q(lag-1,j)-q(lag,lag)*q(lag-1,lag-j); end; end; output; end; run; symbol interpol=needle cv=blue ci=black value=dot height=1 width=1; proc gplot data=a; title1 'Theoretical ACF for MA(2) Process'; title2 'with theta1 = 1.4 and theta2 = -0.6'; plot rho*lag; run; title1 'Theoretical PACF for MA(2) Process'; title2 'with theta1 = 1.4 and theta2 = -0.6'; plot phijj*lag; run;