endogenous_prior with missing observation

Hi dynare team,
(Sorry if I posted in the wrong place, I just realised that gitlab seems for developers only)
In v4.6.2, endogenous_prior cannot work with missing observation, but this is not pointed out in the Reference Manual.
I suppose a naive way to fix this is to exclude any period or variables with missing observations in the calculation of statistics.
Currently, I modified the code as follows but not sure if this is statistically correct. Is there a better way to make this work?

Ydemean(:,j)=Y(:,j)-mean(Y(:,j),'omitnan');  
Fhat=std(Ydemean,1,'omitnan').^2';  
for j=1:n
    Ydemean(:,j)=Y(:,j)-mean(Y(:,j),'omitnan');
end
Fhat=std(Ydemean,1,'omitnan').^2';%Fhat=diag(Ydemean'*Ydemean)/Tsamp;

Sgood=find(~any(isnan(Y),2));
Tgood=length(Sgood);
hmat=zeros(n,Tgood);
% we need ht, where t=1,...,T
for t=1:Tgood
    hmat(:,t)=diag(Ydemean(Sgood(t),:)'*Ydemean(Sgood(t),:))-Fhat;
end

% To calculate Shat we need C0, C1 and C2
for t=1:Tgood
    C0=C0+1/Tgood*hmat(:,t)*hmat(:,t)';
end

for t=2:Tgood
    C1=C1+1/(Tgood-1)*hmat(:,t)*hmat(:,t-1)';
end

for t=3:Tgood
    C2=C2+1/(Tgood-2)*hmat(:,t)*hmat(:,t-2)';
end
Edited by naivej