    if DO_YEAR_FE

        for t_idx = 1 : T-MissingObs-k
%             Y_b(:,t_idx,:) = reshape( A_IV' * squeeze(X_b(1:px,t_idx,:)) , [p,1,N]) ...
%                 + reshape(DATA.MSA_FE_res(:, :), [p, 1, N]) ...
%                 + repmat(DATA.Year_FE_res(:, t_idx), [1, 1, N]) ...
%                 + DATA.Res_Lvl(:, t_idx, :) .* repmat(reshape(SIGN_FLIP(t_idx,:), [1, 1, N]), [p, 1, N]) ;
            if DO_TEST
                for p_idx=1:(p+pz+pp)
                    if p_idx <= p+pz
                        ErrorTerm(p_idx,:)=squeeze( CF_E_opt(p_idx ,sub2ind([T-MissingObs-k,N], reshape(IDX(t_idx,:),N,1)', 1:N  )) )...
                            /(speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)'*DO_SPATIAL,0,N,N));
    %                                     norm( full((speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)',0,N,N))/(speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)',0,N,N)))-eye(N) )
    %                                     transformed_error(p_idx,:,:)=squeeze(original_error(p_idx,:,:))*(speye(N)-sparse(W')*spdiags(IndexM*GroupedRHO(p_idx,:)',0,N,N)) ;
    %                                         display(corr(ErrorTerm(p_idx,:)',squeeze(E_iid(p_idx,t_idx,:))));
                    else
                        pErrorTerm(p_idx-p-pz,:)=squeeze( CF_pE_opt(p_idx-p-pz ,sub2ind([T-MissingObs-k,N], reshape(IDX(t_idx,:),N,1)', 1:N  )) )...
                            /(speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)'*DO_SPATIAL,0,N,N));
    %                                     norm( full((speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)',0,N,N))/(speye(N)-sparse(DistanceMatrix1')*spdiags(IndexM*GroupedRHO_opt(p_idx,:)',0,N,N)))-eye(N) )
    %                                     transformed_error(p_idx,:,:)=squeeze(original_error(p_idx,:,:))*(speye(N)-sparse(W')*spdiags(IndexM*GroupedRHO(p_idx,:)',0,N,N)) ;
    %                                         display(corr(pErrorTerm(p_idx-p-pz,:)',squeeze(pE_iid(p_idx-p-pz,t_idx,:))));
                    end;
                end;
            else
                error('counterfactual currently not set up for this case');
            end;


            evalc('bootstrap_inner_loop_split_Periphery');
        end;
    else
        error('counterfactual currently not set up for this case');
    end;

    Yall_b=[OLD_DATA.Yall(:,1:NoIVLags-k,:), Y_b];
    pYall_b=[OLD_DATA.pYall(:,1:NoIVLags-k,:), pY_b];
