%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Example: Annual U.S. Lumber Production
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Modeling data by Constant Mean Model  z_t=beta+e_t

%%% import data to matlab
load us_lumber.mat

%%% compute sample size
z=US_lumber; 

n=length(z);

%%%  compute mean and standard deviation of sample
beta=mean(z);

STD=std(z);

%%% compute autocorrelations for sample from lag=1 to 6

r=zeros(1,6);

for i=1:6 
    r(i)=auto_corr(z,i);
end

%%% show the autocorrelation valuse on screen
[1:6; r]


%%% compute forecast error 

forecast_error=STD*sqrt(1+1/n);

%%% compute 95% forecast confidence interval 

forecast_up=beta+forecast_error*norminv(0.975,0,1);

forecast_down=beta+forecast_error*norminv(0.025,0,1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Updating forecasts 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Z_1976=MEAN(z); New observation z_1977 now become available.

z_1977=37520;

% Updating beta to beta_1997 and forecast to Z_1997
beta_1977=beta+1/(n+1)*(z_1977-beta); 

Z_1977=beta_1977;


% show one step predition of 1977 on screen. First value is the observation
% of 1977, second value its predition for 1978

[z_1977 Z_1977]
