Hi Everyone,
I'm struggling with storing the index of a random seed in a file to be used for future replication. According to the help file of set seed, we can store the index using the command local and refer to it later. It worked well as below.
(I cannot use set seed because I'll actually do it in a loop for 10000 times. If I set seed for each simulation, the result won't be totally random according to the help file of set seed. So the general idea here is that I do the 10000-times simulation totally randomly for the first time, and I would like to store the 10000 index used within. And the goal would be that in the future anybody can replicate my results by referring to the index I stored.)
sample 5, count
local state = `c(rngstate)'
*replicate
set rngstate `state'
sample 5, count
However, I need to store the index in a separate file instead of a local variable. I tried to do that by storing the `c(rngstate)' as a string variable.
sample 5, count
gen state = "`c(rngstate)'"
keep state
save "seed"
I was hoping that others can retrieve the index by the following code:
*replicate
merge m:1 loop using "seed"
set rngstate state
sample 5, count
By displaying, I confirmed that this string variable and the local variable mentioned above has the exact same format (very long string). State returned that 'state' is an invalid mt64 state after the line "set rngstate state".
And I actually figured out why that error message pops up: c() is something that can only be referred to but not assigned. Now I have no idea how I should proceed.
I really appreciate any advice!
I'm struggling with storing the index of a random seed in a file to be used for future replication. According to the help file of set seed, we can store the index using the command local and refer to it later. It worked well as below.
(I cannot use set seed because I'll actually do it in a loop for 10000 times. If I set seed for each simulation, the result won't be totally random according to the help file of set seed. So the general idea here is that I do the 10000-times simulation totally randomly for the first time, and I would like to store the 10000 index used within. And the goal would be that in the future anybody can replicate my results by referring to the index I stored.)
sample 5, count
local state = `c(rngstate)'
*replicate
set rngstate `state'
sample 5, count
However, I need to store the index in a separate file instead of a local variable. I tried to do that by storing the `c(rngstate)' as a string variable.
sample 5, count
gen state = "`c(rngstate)'"
keep state
save "seed"
I was hoping that others can retrieve the index by the following code:
*replicate
merge m:1 loop using "seed"
set rngstate state
sample 5, count
By displaying, I confirmed that this string variable and the local variable mentioned above has the exact same format (very long string). State returned that 'state' is an invalid mt64 state after the line "set rngstate state".
And I actually figured out why that error message pops up: c() is something that can only be referred to but not assigned. Now I have no idea how I should proceed.
I really appreciate any advice!
Comment