Hello everyone,

I am fitting Negative Binomial count models and generating Negative Binomial draws in the `generated quantities`

block. While the sampling is fine, I get an error because there is an overflow in the random number generator:

```
"Error in sampler$call_sampler(args_list[[i]]) : "
[52] " Exception: gamma_rng: Inverse scale parameter is inf, but must be finite! (in 'model2152242e4a15e1_CBDmodelnew' at line 106)"
```

For info, the corresponding line is as follows:

```
mufor[pos] = gamma_rng(phi,phi/exp(k));
```

After analyzing the sampling, it turns out that in the first 20-50 iterations, `k`

takes relatively high values before converging. To solve this issue, I would then have two questions:

- Is it possible to define a conditional statement in the
`generated quantities`

block which depends on the iteration development, such that for e.g. for the first 100 iterations, the output is zero ? - More generally, is it possible to define a
`generated quantities`

block which would be evaluated only during sampling and not during warmup?

A temporary solution would be to define a conditional statement and say that if `k`

is too high, then the output is zero but I guess there must be a more elegant and general solution.

This topic was partly discussed by @bgoodri in this post and @Bob_Carpenter in this discussion but I couldn’t find the answer to my questions.

Thanks for your help!