Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting a seed before a loop : Am I understanding it well?

    Dear Statalist,

    I'm not sure I understand how seeds work, even after having read the documentation. I want my results to be replicable, but also as random as possible. I am trying to predict a continuous value for a range of financial products like savings acounts, stocks, etc. using regressions. Therefore, I'm using a loop for each financial product defined in a local. The code involves pseudorandom functions like -rnormal()-.
    Here's a code example:

    Code:
    foreach finprod of local product {
    intreg `finprod'1 `finprod'2 ``finprod'_regressors'
    predict `finprod'_y, xb
    * I skip the useless bit here
    local `finprod'_predicted = `finprod'_y[`i'] + ``finprod'_sigma' * ``finprod'_random'
    }
    ``finprod'_random' involves transformations of `finprod'_y with rnormal(). My question is : If I want results as random as possible, do I just need one seed set before the loop begins, or do I have to store different seeds in a nested loop and include it within my loop of local product, so that each financial product has its own seed?

    Thank you so much for your help !

  • #2
    Originally posted by Adam Sadi View Post
    My question is : If I want results as random as possible, do I just need one seed set before the loop begins, or do I have to store different seeds in a nested loop and include it within my loop of local product, so that each financial product has its own seed?
    My reading of the the same documentation, as well as of other sources, is that you're going to get "as random as possible" by setting the seed once, preferably at the top of the do-file.

    Comment

    Working...
    X