Expectation variable in dynare

I am wondering how the dynare computes expectation of a variable. There is an expectation command which gives me the expected value of a variable, say y. How is E(y) computed? My guess is that dynare uses the policy transition y= f(x) and extrapolates it forward. If so, how does it take draws of the state vector, x. Is it using a random number generator to draw x, pass it through the policy transition function f(.), do it repeatedly and then finally compute the average of all draws?
Thank you for answering.

Are you talking about stochastic simulations? If you have a recursive linear policy function, it is straightforward to evaluate the expectations. The question is which context you are looking at. Within a model-block or when Dynare reports moments?

Thank you for your prompt response. Yes I am talking about stochastic simulation. Based on my model, I have computed expost term premia which is the difference between one period return of a long bond minus the one period spot rate. Since the one period return of a long bond is uncertain now, I wanted to compute the expected term premia. This is where I use the expectation command. Thus this expectation is in the model block. I think it is a linear forecast of expost term premia as you say.
My question is how does dynare feed into the state vector, x to project y. Does it use a random number generator to compute x to project y which is term premium in my case?

If you are considering unconditional moments, the state variable will be integrated out using the solution. Within the model context, it’s always conditional expectations, i.e. the value of the state variables within the current period.

Thank you. I understand this. My question is: how is the conditional expectation computed by dynare within stochastic simulation environment.
The second question is: where do we see this conditional expectation series in the worksheet?

Which worksheet are you talking about? Is your question how to extract a time series of that conditional expectations?

Yes. That is exactly what I want. I want to extract the conditional expectation series. I presume all these info should be in the workspace after I run the code.

I also like to know the algorithm dynare uses to compute conditional expectation of y given x. Does it use random number generator to glean x and then forecast y?

Yes, you need to specify the periods-option of stoch_simul. Starting from the steady state, Dynare will draw random shocks from the specified distribution and then provide the simulated series.

Many many thanks for clarifying.