As suggested by Clyde
You can use the parallel module to do such task (which was just published on the Stata Journal, https://journals.sagepub.com/doi/ful...36867X19874242) In general, parallelization is made for data, but you can skip passing data and in essence, run multiple stata sessions simultaneously each one doing something different, like different sets of simulations. To do such, you can make use of the parallel macros, here is an example: https://github.com/gvegayon/parallel...nstance-macros
Here is another example from the manual: https://rawgit.com/gvegayon/parallel.../parallel.html
HIH
Originally posted by Clyde Schechter
View Post
Code:
clear all set more off set trace off parallel setclusters 4 cap drop // Generating a variable called code that goes from 1/4 sysuse auto set seed 112321 gen code = floor(runiform()*4) + 1 tab code /* code | Freq. Percent Cum. ------------+----------------------------------- 1 | 20 27.03 27.03 2 | 11 14.86 41.89 3 | 21 28.38 70.27 4 | 22 29.73 100.00 ------------+----------------------------------- Total | 74 100.00 */ // Storing save mytempdata, replace clear // Program that stores a dataset for program myprogram use if code == $pll_instance using mytempdata.dta, clear collapse (mean) price rep78 (max) code save dataset_$pll_instance.dta, replace end // Processing the data and taking a look at the datasets parallel, prog(myprogram) nodata: myprogram price ls dataset_*.dta /* -rw-rw-r-- 1 george george 907 Sep 21 09:28 dataset_1.dta -rw-rw-r-- 1 george george 907 Sep 21 09:28 dataset_2.dta -rw-rw-r-- 1 george george 907 Sep 21 09:28 dataset_3.dta -rw-rw-r-- 1 george george 907 Sep 21 09:28 dataset_4.dta */ // Now appending (using parallel append) parallel append, do(di) e("dataset_%g.dta, 1/4") list /* +------------------------------------------+ | price rep78 code dta_source | |------------------------------------------| 1. | 6,292.5 3.3 1 dataset_1.dta | 2. | 4,489 3.5 2 dataset_2.dta | 3. | 6,532.1 3.35 3 dataset_3.dta | 4. | 6,537.5 3.52632 4 dataset_4.dta | +------------------------------------------+ */ // Removing files using shell !rm dataset_*.dta mytempdata.dta
Here is another example from the manual: https://rawgit.com/gvegayon/parallel.../parallel.html
Code:
program def myprog gen x = $pll_instance gen y = $PLL_CHILDREN // For the first child process if ($pll_instance == 1) gen z = exp(2) // For the second child process else if ($pll_instance == 2) { summ price gen z = r(mean) } // For the third and fourth child processes else gen z = 0 end
Comment