clear; clc; close all;

%set directory
cd('/Users/julioortiz/Dropbox/ME/replication');
addpath '/Users/julioortiz/Dropbox/ME/replication/code/functions';

macrovar=["rgdp" "pgdp" "cpi" "emp" "unemp" "rconsum" "rfedgov" "rslgov" "rnresin" "rresinv" "tbill" "tbond" "housing" "indprod"];

Encompassing_Weights = zeros(length(macrovar),4);

xmat    = zeros(length(macrovar),4);
xmat_se = zeros(length(macrovar),4);

for i=1:length(macrovar)
clear fe fr lfe Y 

%% First, solve for realized macro parameters
dat_actrt=readmatrix(strcat('processed_data/',macrovar(i),'_actuals.csv'));
act_rt=dat_actrt(:,3);
tStart=tic;
[xvec,fval,g,H]=filterfnc_ar2_H(act_rt);
xmat(i,:) = xvec;
xmat_se(i,:) = sqrt(diag(inv(H)));
tEnd=toc(tStart);
fprintf('Parameters estimated in %d minutes and %f seconds.\n',floor(tEnd/60), rem(tEnd,60));

end

[macrovar' xmat(:,2:4)] %point estimates
[macrovar' xmat_se(:,2:4)] %std errors