Hello there. I would like to know and learn how Stata staff usually does when programming a statistical method that involves the sum of an infinite series. Suppose that each subject

\[ \sum_{y=0}^{\infty} f(Y_i)^{X_i} [1-f(Y_i)]^{1-X_i} \biggl( \frac{\lambda_i^{Y_i}}{Y_i!}e^{-\lambda_i} \biggl) \]

The only way I know for the moment is to use the while loop and do the summation from

I know that, for certain forms of continous variables, Stata performs Gauss–Hermite quadrature to approximate the values of integrals, and the undocumented Mata function _gauss_hermite_nodes() can help us to do so. I wonder whether there are Stata/Mata functions that can help out in approximating the sum of an infinite series for discrete variabels.

Thanks.

*i*in a sample of size*n*has two random variables: a latent variable**follows a Poisson distribution with mean***Y*_{i}**, and an observed variable***λ*_{i}**follows a Bernoulli distribution with probability***X*_{i}**that is certain function of the first variable, i.e.***π*_{i}**=***π*_{i }*f*(**). Does Stata (Mata in particular) provide any function(s) for approximating the following summation?***Y*_{i}\[ \sum_{y=0}^{\infty} f(Y_i)^{X_i} [1-f(Y_i)]^{1-X_i} \biggl( \frac{\lambda_i^{Y_i}}{Y_i!}e^{-\lambda_i} \biggl) \]

The only way I know for the moment is to use the while loop and do the summation from

**and stop the loop when the change between iterations is smaller than a certain value, e.g.***y=0***. However, this way is inefficient, because subjects have different***1e-8***and***λ*_{i}**, and the numbers of loop to achieve the stop criterion vary over subjects. Therefore I am looking for more clever methods.***X*_{i}I know that, for certain forms of continous variables, Stata performs Gauss–Hermite quadrature to approximate the values of integrals, and the undocumented Mata function _gauss_hermite_nodes() can help us to do so. I wonder whether there are Stata/Mata functions that can help out in approximating the sum of an infinite series for discrete variabels.

Thanks.

## Comment