I would like to ask questions related with welfare calculation under the optimal policy. My computation basically follows this paper:

Let me summarize the main steps:

Suppose we have a separable utility function: W_t =\displaystyle \mathbb{E}_t\sum^{\infty}_{j=0}\beta^j\left[\frac{{C_{t+j}}^{1-\sigma}}{1-\sigma}-\chi \frac{{N_{t+j}}^{1+\phi}}{1+\phi}\right].

Specifically, in the baseline Competitive Equilibrium (CE) case, we define the conditional welfare: W^b_t = W^{Cb}_t+W^{Nb}_t,
in which W^{Cb}_t = \displaystyle \mathbb{E}_t\sum^{\infty}_{j=0}\beta^j\frac{{C^b_{t+j}}^{1-\sigma}}{1-\sigma}, and W^{Nb}_t = \displaystyle -\mathbb{E}_t\sum^{\infty}_{j=0}\beta^j\chi \frac{{N^b_{t+j}}^{1+\phi}}{1+\phi},
where C^b_{t+j} and N^b_{t+j}, for j = 0,1,\dots, are consumption and labour sequences when the economy achieves the CE.

Similarly, W^{Ca}_t and W^{Na}_t are the partial conditional welfare when the economy is in an alternative policy regime.

So at the outset of t: \displaystyle W^b_t = \mathbb{E}_t \sum_{j=0}^{\infty} \beta^j \left[ \frac{\left(\left(1+\Delta^{con}\right)C^a_{t+j}\right)^{1-\sigma}}{1-\sigma} - \chi \frac{{N^a_{t+j}}^{1+\phi}}{1+\phi} \right].
Work out \Delta^{con} implicitly: \displaystyle \Delta^{con} = \left[ \frac{W^b_t-W^{Na}_t}{W_t^{Ca}}\right]^{\frac{1}{1-\sigma}}-1.

Now my question is how to compute W^{Ca}_t and W_t^{Na} in a Ramsey context?

First, we know W^b_t under the CE can be derived by oo_.dr.ys(W^b_t)+0.5*oo_.dr.ghs2.

Then according to the new functionality in Dynare 4.7:

If the alternative policy is a Ramsey type, by evaluate_planner_objective, we know W^a_t.

But how to split this value into two parts, W^{Ca}_t and W_t^{Na}?

I guess you want to have conditional welfare at the deterministic steady state.

Have you tried to explicitly define W_t^{Na} in the Ramsey model, i.e. W_t^{Na}=\chi \frac{\left(N_t^b\right)^{1+\phi}}{1+\phi}+\beta E_t W_{t+1}^{Na}
That should allow you to back out W_t^{Ca} given the W_t^{a} provided.

(BACKGROUND)
Yes, I need conditional welfare in both the baseline and the alternative regime.

For the baseline, the Competitive Equilibrium (CE) scenario, it is indeed perturbed around its deterministic steady state, the concept that is also recently discussed in the thread:

For the Ramsey case, I’m not sure whether the economy is approximated around the Ramsey steady state or somewhere else, after all I don’t see Dynare’s report about this sort of steady state.

But this seems to be not important. Suppose Dynare can compute the true conditional welfare of the Ramsey. Then the merit of partial welfare is that it allows the Ramsey case and the CE case to be compared at the same initial point, probably CE’s deterministic steady state, if I understand the following equality correctly:

The BK violation comes from differences in the computed steady states. They may not be unique.

It turns out you cannot have additive parts of the welfare function in the model as they will introduce a singularity. The big number you encounter comes from Dynare replacing the resulting NaN with a large number. 4.7 should have a warning in that case. Now to the workaround. What you can do is have the components of utility as variables in the model:

% WelfareC
[name='UC']
UC = C^(1-SIGMA)/(1-SIGMA);
[name='UN']
UN = -CHI*N^(1+PHI)/(1+PHI);

and then manually compute the decomposition based on the codes in evaluate_planner_objective after running the model. Here, it would be

%% housekeeping to have access to relevant info
if isempty(options_.qz_criterium)
options_.qz_criterium = 1+1e-6;
end
dr = oo_.dr;
ys=oo_.dr.ys;
exo_nbr = M_.exo_nbr;
nstatic = M_.nstatic;
nspred = M_.nspred;
beta = get_optimal_policy_discount_factor(M_.params, M_.param_names);
%% Original objective
[U,Uy,Uyy] = feval([M_.fname '.objective.static'],ys,zeros(1,exo_nbr), M_.params);
%% override original objective and instead read out UC (or UN if desired); needs to be defined in model-block
UC_pos=strmatch('UC',M_.endo_names,'exact');
U=ys(UC_pos); %get steady statee
Uy=zeros(size(Uy));
Uy(UC_pos)=1; %first derivative is 1 for defined variable, zero for all others
Uyy=sparse(zeros(size(Uyy))); %all second derivatives are zero
Gy = dr.ghx(nstatic+(1:nspred),:);
Gu = dr.ghu(nstatic+(1:nspred),:);
Gyy = dr.ghxx(nstatic+(1:nspred),:);
Gyu = dr.ghxu(nstatic+(1:nspred),:);
Guu = dr.ghuu(nstatic+(1:nspred),:);
Gss = dr.ghs2(nstatic+(1:nspred),:);
gy(dr.order_var,:) = dr.ghx;
gu(dr.order_var,:) = dr.ghu;
gyy(dr.order_var,:) = dr.ghxx;
gyu(dr.order_var,:) = dr.ghxu;
guu(dr.order_var,:) = dr.ghuu;
gss(dr.order_var,:) = dr.ghs2;
Uyy = full(Uyy);
Uyygygy = A_times_B_kronecker_C(Uyy,gy,gy);
Uyygugu = A_times_B_kronecker_C(Uyy,gu,gu);
Uyygugy = A_times_B_kronecker_C(Uyy,gu,gy);
%% Unconditional welfare
oo_=disp_th_moments(dr,M_.endo_names(dr.order_var(nstatic+(1:nspred))),M_,options_,oo_);
oo_.mean(isnan(oo_.mean)) = options_.huge_number;
oo_.var(isnan(oo_.var)) = options_.huge_number;
Ey = oo_.mean;
Eyhat = Ey - ys(dr.order_var(nstatic+(1:nspred)));
Eyhatyhat = oo_.var(:);
Euu = M_.Sigma_e(:);
EU = U + Uy*gy*Eyhat + 0.5*((Uyygygy + Uy*gyy)*Eyhatyhat + (Uyygugu + Uy*guu)*Euu + Uy*gss);
EW = EU/(1-beta);

Yes, posting your comments and modified codes in the forum will benefit other users.

Please give me some days to digest them. After that, I may ask questions related with the welfare comparison between OSR and Ramsey, since I still feel some problem in the conditional welfare reported by Dynare 4.7. This problem does not occur in previous versions. Be patient. Thank you!