<p>My understanding is that the standard advice is to randomly select a seed value, and then keep that seed for your entire analysis. This allows the same computer code to give identical results each time. </p>

<p>See, for example, the <a href="https://www.stata.com/manuals13/rsetseed.pdf" rel="nofollow noreferrer">Stata manual</a>:</p>

<blockquote>
  <p>Stata’s random-number generation functions, such as runiform() and
  rnormal(), do not really produce  random  numbers.  These  functions 
  are  deterministic  algorithms  that  produce  numbers  that can  pass
  for  random. runiform() produces  numbers  that  can  pass  for 
  independent  draws  from  a rectangular distribution over[0,1);
  rnormal()produces numbers that can pass for independent draws from
  N(0,1).  Stata’s random-number functions are formally called
  pseudorandom-number functions.The  sequences  these  functions 
  produce  are  determined  by  the  seed,  which  is  just  a  number 
  andwhich  is  set  to  123456789  every  time  Stata  is  launched.
  ... If you record the seed you set, pseudorandom results such as
  results from a simulation or imputed values  from mi impute can  be 
  reproduced  later.  <strong>Whatever  you  do  after  setting  the  seed, 
  if  you  set the seed to the same value and repeat what you did, you
  will obtain the same results</strong> ... It does not really matter how you
  set the seed, as long as there is no obvious pattern in the seeds that
  you set and as long as you do not set the seed too often during a
  session</p>
</blockquote>

<p>However, if you are using parallelization to do many separate simulations then you need to make sure that you do not use the same seed, or a time based seed, on every node:</p>

<blockquote>
  <p>Properly seed your generator. Even the state-of-the-art Mersenne
  Twister ran into problems early on because the authors had neglected
  the issue of proper seeding....This rule is VITAL if you are going to
  run parallel simulations on a Beowulf cluster for example.The simplest
  way to seed a RNG is to take something like the current time e.g.
  using the time() function found in Unix and most C libraries, which
  returns a 32-bit integer giving the number of seconds since 1st Jan
  1970. ...Hundreds of jobs on different nodes will be starting at almost exactly the same time –therefore many of your jobs will be
  starting with exactly the same seed and therefore those that have the
  same seed will generate exactly the same results(assuming your code
  has no bugs in it).</p>
</blockquote>

<p><a href="http://www0.cs.ucl.ac.uk/staff/D.Jones/GoodPracticeRNG.pdf" rel="nofollow noreferrer">Good Practice in (Pseudo) Random Number Generation for Bioinformatics Applications</a></p>

CC BY-SA 4.0
2019-07-21T01:20:04.227Z
Yup, plus: always run your analysis against different seeds as a robustness check. Present your results for the one seed, but if they’re highly sensitive to the seed value, you have a problem.
dismalscience
CC BY-SA 4.0
2019-07-21T00:49:01.877Z
2019-07-21T00:49:01.877Z
BKay
<p>Suppose we are estimating a linear model utilizing a Markov Chain Monte Carlo technique such as a Gibbs sampler, drawing from the posteriors in a Bayes framework.  Suppose the full sample of data we have is from time <span class="math-container">$t = 1, \dots,\tau\dots, T$</span>, and we want to forecast returns one period ahead using a recursive window starting at time <span class="math-container">$t = \tau$</span> until time <span class="math-container">$t = T$</span>. We have trained the model from time <span class="math-container">$t=1$</span> to time <span class="math-container">$t=\tau$</span>, then we want to forecast returns out of sample at time <span class="math-container">$t=\tau+1$</span>:</p>

<p><span class="math-container">\begin{equation} y_{\tau +1} = \beta' \mathbf{x}_\tau + \sigma \varepsilon_{\tau + 1}, \; \; \varepsilon_{\tau + 1} \sim \mathcal{N}(0,1) \end{equation}</span></p>

<p>When I tried this without setting the seed at each period the error term <span class="math-container">$\varepsilon_{\tau+1}$</span> was so stochastic across the <span class="math-container">$I$</span> iterations of the MCMC algorithm that <span class="math-container">$y_{\tau+1}$</span> was essentially a random walk.  When I set the seed at each period such that the <span class="math-container">$I$</span> iterations in the Gibbs sampler used the same <span class="math-container">$\varepsilon_{\tau+1}$</span> I found much better results in terms of RMSFE.</p>

<p>Should we set the seed in the random number generator in each period <span class="math-container">$\tau$</span>, such that all <span class="math-container">$I$</span> iterations of evaluating <span class="math-container">$y_{\tau+1}$</span> use the same error term <span class="math-container">$\varepsilon_{\tau+1}$</span> when computing this forecast? </p>

CC BY-SA 4.0
2019-07-15T19:14:10.523Z
By seed, do you mean $X_0$? Do you mean seeding the random number generator? If not, can you please update your question to be more precise about what you mean? Thanks.
BKay
CC BY-SA 4.0
2019-07-15T19:16:41.973Z
Thank you for pointing this out, I mean the random number generator.   But I think I have realized the answer to this is to not include the random term in the forecast equation at all.
Sunhwa
<markov-chain><forecasting>
Should the seed be set in forecasting returns in a MCMC
Sunhwa
# Should the seed be set in forecasting returns in a MCMC

(Asked by: username_0 on 2019-07-12)

Suppose we are estimating a linear model utilizing a Markov Chain Monte Carlo technique such as a Gibbs sampler, drawing from the posteriors in a Bayes framework. Suppose the full sample of data we have is from time $t = 1, \dots,\tau\dots, T$, and we want to forecast returns one period ahead using a recursive window starting at time $t = \tau$ until time $t = T$. We have trained the model from time $t=1$ to time $t=\tau$, then we want to forecast returns out of sample at time $t=\tau+1$:

\begin{equation} y\_{\tau +1} = \beta' \mathbf{x}\_\tau + \sigma \varepsilon\_{\tau + 1}, \; \; \varepsilon\_{\tau + 1} \sim \mathcal{N}(0,1) \end{equation}

When I tried this without setting the seed at each period the error term $\varepsilon\_{\tau+1}$ was so stochastic across the $I$ iterations of the MCMC algorithm that $y\_{\tau+1}$ was essentially a random walk. When I set the seed at each period such that the $I$ iterations in the Gibbs sampler used the same $\varepsilon\_{\tau+1}$ I found much better results in terms of RMSFE.

Should we set the seed in the random number generator in each period $\tau$, such that all $I$ iterations of evaluating $y\_{\tau+1}$ use the same error term $\varepsilon\_{\tau+1}$ when computing this forecast?

**Tags:** markov-chain, forecasting
> **Comments:**
> **username_1**: By seed, do you mean $X_0$? Do you mean seeding the random number generator? If not, can you please update your question to be more precise about what you mean? Thanks.  
> **username_0**: Thank you for pointing this out, I mean the random number generator.   But I think I have realized the answer to this is to not include the random term in the forecast equation at all.  

---

## 1 answers

### Answer by username_1 on 2019-07-21. Score: 2 | Accepted answer

My understanding is that the standard advice is to randomly select a seed value, and then keep that seed for your entire analysis. This allows the same computer code to give identical results each time.

See, for example, the [Stata manual](https://www.stata.com/manuals13/rsetseed.pdf):

> Stata’s random-number generation functions, such as runiform() and
> rnormal(), do not really produce random numbers. These functions
> are deterministic algorithms that produce numbers that can pass
> for random. runiform() produces numbers that can pass for
> independent draws from a rectangular distribution over[0,1);
> rnormal()produces numbers that can pass for independent draws from
> N(0,1). Stata’s random-number functions are formally called
> pseudorandom-number functions.The sequences these functions
> produce are determined by the seed, which is just a number
> andwhich is set to 123456789 every time Stata is launched.
> ... If you record the seed you set, pseudorandom results such as
> results from a simulation or imputed values from mi impute can be
> reproduced later. **Whatever you do after setting the seed,
> if you set the seed to the same value and repeat what you did, you
> will obtain the same results** ... It does not really matter how you
> set the seed, as long as there is no obvious pattern in the seeds that
> you set and as long as you do not set the seed too often during a
> session

However, if you are using parallelization to do many separate simulations then you need to make sure that you do not use the same seed, or a time based seed, on every node:

> Properly seed your generator. Even the state-of-the-art Mersenne
> Twister ran into problems early on because the authors had neglected
> the issue of proper seeding....This rule is VITAL if you are going to
> run parallel simulations on a Beowulf cluster for example.The simplest
> way to seed a RNG is to take something like the current time e.g.
> using the time() function found in Unix and most C libraries, which
> returns a 32-bit integer giving the number of seconds since 1st Jan
> 1970. ...Hundreds of jobs on different nodes will be starting at almost exactly the same time –therefore many of your jobs will be
> starting with exactly the same seed and therefore those that have the
> same seed will generate exactly the same results(assuming your code
> has no bugs in it).

[Good Practice in (Pseudo) Random Number Generation for Bioinformatics Applications](http://www0.cs.ucl.ac.uk/staff/D.Jones/GoodPracticeRNG.pdf)

> **Comments:**
> **username_2**: Yup, plus: always run your analysis against different seeds as a robustness check. Present your results for the one seed, but if they’re highly sensitive to the seed value, you have a problem.  

---

