# Loop over parameters to find maximized welfare

**URL:** <https://forum.dynare.org/t/loop-over-parameters-to-find-maximized-welfare/12358>\
**Category:** Optimal Policy\
**Created:** [3 September 2018 14:11 UTC](https://forum.dynare.org/t/loop-over-parameters-to-find-maximized-welfare/12358 "2018-09-03T14:11:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [4 September 2018 06:26 UTC](https://forum.dynare.org/t/loop-over-parameters-to-find-maximized-welfare/12358/2 "2018-09-04T06:26:25Z")

</div>

1. In your case, you only need to read out the welfare. As you are not computing a consumption-equivalent, you do not need the function I write.
2. Welfare is a stochastic property of the model, but you are reading out the steady state instead of the unconditional mean. The steady state will always be the same. You need to read out the respective element of `oo_.mean` and for that cannot use `nomoments`. Also, you need to add `welfare` to the variables after `stoch_simul` to get its moments.
3. Are you sure your shock size is correct. It seems you multiply by 100 to have them in percentages. But at second order you cannot do that as the model solution is not certainty equivalent anymore. You will get wrong results. A 1 percent shock is 0.01, not 1.

Use

```auto

dynare welfare_TRY2.mod
rhogrid = 0.6:0.2:1.0;
% result_y = ones(length(rhogrid),1);
welfare_pos=strmatch('welfare',var_list_,'exact');
results_cell = zeros(length(rhogrid),1);
for i = 1:length(rhogrid)

    set_param_value('rho',rhogrid(i))

    info = stoch_simul(var_list_);
    
    if info ==0
        results_cell(i) = oo_.mean(welfare_pos);
    else 
        fprintf('Here is an error!\n');
    end
end

```

[welfare\_TRY2\_steadystate.m](https://forum.dynare.org/uploads/default/original/2X/3/3a66bdc9ee83accae7d43f33b135bab9bc9773e2.m) (5.7 KB)  
[welfare\_TRY2.mod](https://forum.dynare.org/uploads/default/original/2X/4/4cc28e2dac266421d234b54c97cfcca38bfbadf3.mod) (8.1 KB)  
[Run\_welfare\_TRY\_outside2.m](https://forum.dynare.org/uploads/default/original/2X/5/59e66441eeef0e45872356713f9fbe9694884a83.m) (677 Bytes)

---

_[View the full topic](https://forum.dynare.org/t/loop-over-parameters-to-find-maximized-welfare/12358)._
