Announcement

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

  • Problem with parallel: parallelize a loop

    Hello to all,
    I am not very strong in STATA but I wrote a program. I wanted to parallelize a loop. But, while searching, I didn't find a commercial way to parallelize it directly. So I integrated the loop in a program that I parallelized afterward.

    The objective is to make regression under several sub-samples chosen with the variable "rp_partner_rank".

    Then I have to get information about my variable of interest: lag_fdi_in_all
    and the stocks in the variables.

    Code:
    program define savereg
    qui {
    sum rp_partner_rank
    
    forvalues i = `r(min)' (1) `r(max)' {
    
    xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_all $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
    
    lincom _b[lag_fdi_in_all], l(95)
    replace beta = r(estimate) in `i'
    replace se = r(se) in `i'
    replace i_pos = `i' in `i'
    replace lb_95 = r(lb) in `i'
    replace ub_95 = r(ub) in `i'
    
    lincom _b[lag_fdi_in_all], l(90)
    replace lb_90 = r(lb) in `i'
    replace ub_90 = r(ub) in `i'
    
    lincom _b[lag_fdi_in_all], l(99)
    replace lb_99 = r(lb) in `i'
    replace ub_99 = r(ub) in `i'
    
    
    }
    }
    
    end
    preserve
    
    drop beta se i_pos lb_* ub_*
    g i_pos = .
    g beta = .
    g se = .
    g lb_90 = .
    g lb_95 = .
    g lb_99 = .
    g ub_90 = .
    g ub_95 = .
    g ub_99 = .
    
    parallel prog(savereg): savereg
    *parallel: savereg
    *parallel do "$Code\saveregdo.do"
    *drop if beta==.
    
    keep beta se i_pos lb_* ub_*
    
    
    parallel append, do(savereg) prog(savereg) e(3)
    twoway rarea ub_90 lb_90 i_pos , astyle(ci) || ///
    line beta i_pos
    
    save "$DataCreated\asup", replace
    restore

    But the code doesn't work, I have tested several ways with even the "parallele do" command, saving the loop in a do file. but the results are not what I expect. Please can you help me?
    here are the error results

    Code:
    .                                 parallel prog(savereg): savereg
    --------------------------------------------------------------------------------
    Parallel Computing with Stata (by GVY)
    Clusters   : 4
    pll_id     : l9d9vacs17
    Running at : G:\Etude et biblio\Université\tours\Master2 IE\Econometrie avancee\memoire\donn
    > ees\Code
    Randtype   : datetime
    Waiting for the clusters to finish...
    cluster 0002 Exited with error -199- while running the command/dofile (view log)...
    cluster 0003 Exited with error -199- while running the command/dofile (view log)...
    cluster 0004 Exited with error -199- while running the command/dofile (view log)...
    cluster 0001 Exited with error -199- while running the command/dofile (view log)...
    --------------------------------------------------------------------------------
    Enter -parallel printlog #- to checkout logfiles.
    --------------------------------------------------------------------------------
    
    .
    How should I parallelize this loop?

  • #2
    Hi Lucien,
    The program syntax for parallel is probably the most appropriate here.
    Looking over my own code, I think the issue is that the syntax you use requires a comma after the initial parallel call -
    Code:
     
    parallel, prog(savereg): savereg
    And then you just need to remove the other calls to parallel below (which I assume are included only as examples of the various parallel options you have employed).
    Let me know if this solves your problem. If it does not, please show the logfile output - this will help us diagnose any further problems.
    All the best,
    Matt
    Last edited by Matthew Alexander; 26 Dec 2021, 07:34.

    Comment


    • #3
      Hello Matthew,
      Thank you for your feedback.
      I did it was an error. So I restarted STATA and limited the loop to the first 10 iterations.
      But STATA returns an error.
      and I can't see the log file.
      Here is the code.


      .
      Code:
                               program define savereg 
        1.                                 qui {
        2.                                         sum rp_partner_rank, d
        3.                                         p_partner_rank, d
        4.                                         
      .                                         forvalues i = `r(min)' (1) 10 {
        5.                                                         
      .                                                         di `i'
        6.                                                         
      .                                                                 xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_al
      > l $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
        7.                                                                 *eststo
      .                                                                 lincom _b[lag_fdi_in_all], l(95)
        8.                                                                 replace beta = r(estimate) in `i'
        9.                                                                 replace se = r(se) in `i'
       10.                                                                 replace i_pos = `i' in `i'
       11.                                                                 replace lb_95 = r(lb) in `i'
       12.                                                                 replace ub_95 = r(ub) in `i'
       13.                                                                 
      .                                                                 lincom _b[lag_fdi_in_all], l(90)
       14.                                                                 replace lb_90 = r(lb) in `i'
       15.                                                                 replace ub_90 = r(ub) in `i'
       16.                                                                 
      .                                                                 lincom _b[lag_fdi_in_all], l(99)
       17.                                                                 replace lb_99 = r(lb) in `i'
       18.                                                                 replace ub_99 = r(ub) in `i'
       19.                                                         
      .                                         
      .                                         }
       20.                                 } 
       21.                         
      .                         end
      
      . 
      end of do-file
      
      . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
      
      .                                 parallel setclusters 4
      N Clusters: 4
      Stata dir:  C:\Stata 16 MP/StataMP-64.exe
      
      . 
      end of do-file
      
      . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
      
      .                         preserve
      
      .                                 
      .                                 *drop beta se i_pos lb_* ub_*
      .                                 g i_pos = .
      (105,254 missing values generated)
      
      .                                 g beta = .
      (105,254 missing values generated)
      
      .                                 g se = .
      (105,254 missing values generated)
      
      .                                 g lb_90 = .
      (105,254 missing values generated)
      
      .                                 g lb_95 = .
      (105,254 missing values generated)
      
      .                                 g lb_99 = .
      (105,254 missing values generated)
      
      .                                 g ub_90 = .
      (105,254 missing values generated)
      
      .                                 g ub_95 = .
      (105,254 missing values generated)
      
      .                                 g ub_99 = .
      (105,254 missing values generated)
      
      .                                 
      .                                 parallel, prog(savereg): savereg
      invalid '16' 
                       stata():  3598  Stata returned error
      parallel_export_programs():     -  function returned error
           parallel_write_do():     -  function returned error
                       <istmt>:     -  function returned error
      r(3598);
      
      end of do-file
      
      r(3598);
      
      .
      I also send you the log file of the first command without the comma: parallel prog(savereg): savereg


      Code:
      . parallel printlog 1, e(mkduc8jb13)
      --------------------------------------------------------------------------------
      beginning of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__pllmkduc8jb13_do0001.log-
      --------------------------------------------------------------------------------
      
      
      running C:\Stata 16 MP\ado\base\profile.do ...
      
      
      . capture {
      -------------------------------------------------------------------------------
      > -
      Parallel computing with stata (by GVY)
      -------------------------------------------------------------------------------
      > -
      cmd/dofile   : "savereg"
      pll_id       : mkduc8jb13
      pll_instance : 1/4
      tmpdir       : C:\Users\LUCIEN~1\AppData\Local\Temp/__pllmkduc8jb13_tmpdir0001/
      date-time    : 14:26:51 26 Dec 2021
      seed         : XAA00000000000034b66fdccbc2d01d8dff9ef76b7e4b78f7a81bd6f474e512d
      > ee503525699582dc945e6945b3ad80e9c26b9d407e41790cd87105c237514d21b685212c09db8
      > 0f6950df0285825819b246f4f523a07a1d912b5fa05e1f7e7d5c13894058bf5b301d36838795b
      > 05535ee3122abe05683552c05875b94e171b837f045356169c8fce39a6961674f4694e750dfbe
      > a386f512d84fc07563d7e1d9b96f480a44beb21e2c103c764383f90f2e12c94f0f6e78000740d
      > 59980e6399a83de28cc16f92334d0f13c6a3c648c35497690804dcbde7d73d8214eb2f17e6883
      > 6da0d0da2aec032d45d92b95667e582e9876e7c01a18d6165d8ba75852e645924bc0999f8fce4
      > 9edf535bdb3887839de5fdeb60d0778c837d58ecb84f59672fac1c541d873541bd16bdd6f68a3
      > 574e676d33a68ab3191dc07ce5b4b43304e459f3841b2f30bd71df58162c95f48233e8fb3ecc0
      > a12c1cb794929c72cb4456c8900b060fff8c90b152c6236494ad23a8b4391c42076a4ca38c827
      > 2506ac4f4a31b1820e44ac36b68b4ddfea53e7b62dae14c8ffd16bd6c8033de0415cc845da541
      > 93995b378423baec66fb9ea6cc16ff303e1a19abb9265b5903c41ae8a8383d80ed75467ee6e81
      > ecae9d22f006fdf16da22b39e865b6f2a55a78b6acc67e10b70d76faca9c8dbb215826a2044a9
      > 43d03e2eef53c0aae30ccf80d30fdaba65b8d5ec553317ad8ef7bc67f7885f976287ce223e569
      > 02ef3191296c2e71544b96db7826e06d8bc9d29b89f2af838827eb4e5a62665b98c607eceb816
      > 22e2d1a1ebb69ae0fbf38afa8071705b41db29745a9fa5e9ab4644d13e73ccd2506d31eb7e904
      > e78a0bcd58016f87831201e6466716813a0ff81d8288f255aac37f8929c3c440ab384ba348303
      > dea87c6a4c08738fa19f3caca159ece5c116a5a4830386d1d7db004378705fab320cd368bc5c6
      > b95b4fcfaedcb2961bc0b260459254da7dae7469777ad107bcb5e9e1d8ea33ba721221e6ddce5
      > 702d60e5482a913d6dd60aea6e0aea48a36160f30ce53cc717019f954c533ebfc8ae5fda91269
      > 82599f36ed41cdff01919f2ff3cd809a9b11d4470d9768152705b3f34e93c6ab9fe068b93e0d2
      > 752a119947edada7549594a21c09eb74912aafee58630649447b5e511619d28c5925dbe6c9276
      > cacbdc142d8da998be2074ef900b969ca31805ebe2500d6612f6e267c27877df963b8abc4902b
      > 6389ef01489d1bc145634800a5b45a85b711a3b157dc7e825c9a8fb7330b2cc76caf9189e7e35
      > 3b15b464bd62726ed58252070ca23d7b6781e6553ad656f7ee92a866f6828037fcb03464aba91
      > 46ae8eb4f9292fb493bbca56cc88bf5122c839e55fbd1a35491a568a43fbd7483de63caa307db
      > 8b2ad06f67235dd1ac32f53d62da03bbab03d0b686527ed81502b38ab4044b583718128dac792
      > 81441791b2849a3b638ec5136ee17118031b806e47b3c940324022606c0d2820bfed919e847eb
      > 517426393f93200a5b711479a9cb89f42264675ff319112da81c6696e982204df0a29354335ac
      > af32a31d67968aa025cb882d4e3067918e96e397270ab6d8e7926bf6640475a1a1a11f47a1ad8
      > 5bb516b3a09554b1cc70cf72dd0015a8f1ce3ed2c41288356947ae49060e21a23d585ad0a1411
      > 676b5cf2b8be1d502a7faee6bb6f50dc963a3dde133d4e523fa9ad3b048db7b5e156e2fd7f690
      > a75aef7d1aad4716450fafb1f55c6b1ec77dca0b876e360ee943abb0ccc0f3e51fea6fcbf3c7f
      > a0be1b48658db99698dd6cbf4264cfb0095ed424f8decb784fe9d112b262a7ce41a7f334b694f
      > 1400da7ad259225667cc22c1b80d11e2e33fcbaf9f870f1dfe6ecd1a9501e8712d2c09afc93ff
      > 39b06353c9b5d9e0bb9971e8eabc249c3ef33d34560bf9679ce3f5d2549c16a96964c3bff0917
      > 30dc8fff8e5220f4dc9d4540b317c5edb7de559ae4b9bbe7ea4d3bf47b6103a806a607cece17c
      > 1d89fa6befaa3bce4972e1eeb758a456ff46902f60009010d65b3407f7895b4de055fd7cc3a9d
      > 59087a9ce647bf4f88df2efaf02f3d739ff9eb032a63f3b72429f97b1da7668b94cec6d365796
      > 8f5be4065a9558c5cf5f406a03fdcadf4c7cdeb4321e92976d2c690bfdaea651bc85f3e0cb85c
      > c8695c181b166c9d392d18f8f680854194a86c59ff5b4f4a77bdb294b59e3476edd44e4e4fa7e
      > 010436578206fea5fd0e6a37d925cba6f6a6098009de44b7fb10dd18033a2f6cd68385b5938b8
      > 20b221601475fb7be3ee3ba00c448f8ae5a55546d07fc1842accae22873313397bc793e8fe69c
      > aef7db993b5c5cf50f3bcf96964ee9f666114ff8ee0ce20916d33d0977a332a21da4d0828e184
      > 4872f662ae6cf9f5cbb05581982893719c4b05006ccf36932fd7dc5bb72948be12a1a10a1ffb0
      > 4f1a5517e86efe49ccd3d6f1bc56b00ca935f2fade262ee127b0d1d78dea2fb222eb04e8f8d47
      > 813da72fbf9185bc01ac132816e8bad33903e3f8625b77786d23bfc8ecf61643dabb54e589a4d
      > d8e329d1dd023e9a570c857b2f5af1bb5820d3f71841f59a8d48b918a9b571030bba4497af903
      > f3fe645bbee5436df5f3059f31c66d3d148f237f2d28f6ceecd081151089951f4b05822c42741
      > ad6910da015badc61b691bfd76f7af9799053e9568f7b23cd97ddbacd8c98968e4c8709b32ccb
      > 0b35d20903eeaa52baa68022ca478c0be8c571f3f47f7c08a2c4cf3fb5521b5ef9cccfcf58bf8
      > 246feb25726d3a311902105b927e76706f851c97b7ae5077401eb7096458596587f20b483973e
      > ab1939f639d3c24dca67099bd9b721c162dc2729919f0135df8077177aef8764b5d616382e00d
      > 978c65d25dd1558aa1a3d2bc76be6fe20805d4cd63a9f4c915a0c8e0490b55d766fb4ff5bb503
      > b51694d37a836bf3a7c0717e410c0cae5fec8b93ba34464b31409082b0abc306d0a1f6e389f54
      > ee2c4770f36fd069c17d6fc5f7d7a4d66dad4dce2b485d4c821d5849c4d3ae9851da9622f6f8c
      > 1ea50d1b190e0a5b9ca5349fe5ef488a52b02201451cac4c4cfef96987399d561014705845334
      > f2d13b666e3a4046522eda434cc0c32cb7e1ff57b49eb881155d3cce3e98aa2d234ff4727378a
      > 2e5a53b9ce3067ee2d8b061a099dd828b1f4f23d77659792a13b44fe45c5a4898f50bca0ef194
      > 8e35b65ac97a5291d1eb19c2d6de41d629de03e38adb6c957b6c3d53da17b900fe42770e962bf
      > c66861c8e658bf6bf6efc3b53b8b96007af702a6569f9b18aa066a709ae23d2cde31345131a19
      > 50cdf946b60d23aa751ba29a3938c2e2dff922e4d2dd3d1030c86e379f6885059a7d4e20c939c
      > 63513c0a1022a8e280abdbb5fa0b222bb95768041d27e6bfccf8341d4540963e5000d7614e48b
      > d799d161d4d11e64bac5406b17cffc8beb8cbc8dffd7c9f9d996cad0c91844ec0a20622650fc0
      > 3ade4490a5e9852052969acbfeb747d44cb1b7a9bdd34ca65b8b5a1a625e5391a28b1f7578d92
      > 1870001000001381bde
      -------------------------------------------------------------------------------
      > -
      
      . local result = _rc
      
      . if (c(rc)) {
      . cd "C:\Stata 16 MP/"
      . mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllmkduc8
      > jb13_finito0001","while setting memory")
      . clear
      . exit
      . }
      
      . 
      . /* Checking for break */
      . mata: parallel_break()
      
      . 
      . /* Loading Globals */
      . capture {
      
      . if (c(rc)) {
      .   cd "C:\Stata 16 MP/"
      .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllmkdu
      > c8jb13_finito0001","while loading globals")
      .   clear
      .   exit
      . }
      
      . 
      . /* Checking for break */
      . mata: parallel_break()
      
      . capture {
      .     use "C:\Stata 16 MP/__pllmkduc8jb13_dataset" if _mkduc8jb13cut == 1
      . 
      . /* Checking for break */
      . mata: parallel_break()
      .     savereg
      command savereg is unrecognized
      r(199);
      .   }
      
      . if (c(rc)) {
      .   cd "C:\Stata 16 MP/"
      C:\Stata 16 MP
      .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllmkdu
      > c8jb13_finito0001","while running the command/dofile")
      .   clear
      .   exit
      
      end of do-file
      --------------------------------------------------------------------------------
       end of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__pllmkduc8jb13_do0001.log-  
      --------------------------------------------------------------------------------
      
      .
      Thank you

      Comment


      • #4
        Hi Lucien,
        I'm sure we can get this working.
        After seeing your full code, I think that the problem may be that you have defined your program outside of parallel - hence the error message "command savereg is unrecognised".
        The very first line of code should be
        Code:
        parallel initialise 4
        Then your program syntax - and you probably should drop the program before defining it.
        Code:
        capture program drop savereg
        program define savereg
        Let me know how you get on.
        Best,
        Matt

        Comment


        • #5
          I'll add too, that you call to preserve without a corresponding call to restore. So, perhaps you can elaborate more on your intentions here.
          If you want to preserve and restore within parallel, then you include this within your program.

          Comment


          • #6
            Hi Math
            I think I understand what you mean.
            Here is what you want me to do:

            Code:
                        parallel setclusters 4
                        capture program drop savereg
                        program define savereg 
                            qui {
                                sum rp_partner_rank, d
                                p_partner_rank, d
                                
                                forvalues i = `r(min)' (1) 10 {
                                        
                                        di `i'
                                        
                                            xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_all $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
                                            *eststo
                                            lincom _b[lag_fdi_in_all], l(95)
                                            replace beta = r(estimate) in `i'
                                            replace se = r(se) in `i'
                                            replace i_pos = `i' in `i'
                                            replace lb_95 = r(lb) in `i'
                                            replace ub_95 = r(ub) in `i'
                                            
                                            lincom _b[lag_fdi_in_all], l(90)
                                            replace lb_90 = r(lb) in `i'
                                            replace ub_90 = r(ub) in `i'
                                            
                                            lincom _b[lag_fdi_in_all], l(99)
                                            replace lb_99 = r(lb) in `i'
                                            replace ub_99 = r(ub) in `i'
                                        
                                
                                }
                            } 
                        
                        end
                        
                        preserve
                            
                            *drop beta se i_pos lb_* ub_*
                            g i_pos = .
                            g beta = .
                            g se = .
                            g lb_90 = .
                            g lb_95 = .
                            g lb_99 = .
                            g ub_90 = .
                            g ub_95 = .
                            g ub_99 = .
                            
                            parallel, prog(savereg): savereg
                            
                            twoway rarea ub_90 lb_90 i_pos , astyle(ci) || ///
                            line beta i_pos
            
                            save "$DataCreated\asup", replace
                        restore
            I did. But there is always a mistake
            with the comma: parallel, prog(savereg): savereg

            Code:
            . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
            
            .                         parallel setclusters 4
            N Clusters: 4
            Stata dir:  C:\Stata 16 MP/StataMP-64.exe
            
            .                         capture program drop savereg
            
            .                         program define savereg 
              1.                                 qui {
              2.                                         sum rp_partner_rank, d
              3.                                         p_partner_rank, d
              4.                                         
            .                                         forvalues i = `r(min)' (1) 10 {
              5.                                                         
            .                                                         di `i'
              6.                                                         
            .                                                                 xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_al
            > l $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
              7.                                                                 *eststo
            .                                                                 lincom _b[lag_fdi_in_all], l(95)
              8.                                                                 replace beta = r(estimate) in `i'
              9.                                                                 replace se = r(se) in `i'
             10.                                                                 replace i_pos = `i' in `i'
             11.                                                                 replace lb_95 = r(lb) in `i'
             12.                                                                 replace ub_95 = r(ub) in `i'
             13.                                                                 
            .                                                                 lincom _b[lag_fdi_in_all], l(90)
             14.                                                                 replace lb_90 = r(lb) in `i'
             15.                                                                 replace ub_90 = r(ub) in `i'
             16.                                                                 
            .                                                                 lincom _b[lag_fdi_in_all], l(99)
             17.                                                                 replace lb_99 = r(lb) in `i'
             18.                                                                 replace ub_99 = r(ub) in `i'
             19.                                                         
            .                                         
            .                                         }
             20.                                 } 
             21.                         
            .                         end
            
            .                         
            .                         preserve
            
            .                                 
            .                                 *drop beta se i_pos lb_* ub_*
            .                                 g i_pos = .
            (105,254 missing values generated)
            
            .                                 g beta = .
            (105,254 missing values generated)
            
            .                                 g se = .
            (105,254 missing values generated)
            
            .                                 g lb_90 = .
            (105,254 missing values generated)
            
            .                                 g lb_95 = .
            (105,254 missing values generated)
            
            .                                 g lb_99 = .
            (105,254 missing values generated)
            
            .                                 g ub_90 = .
            (105,254 missing values generated)
            
            .                                 g ub_95 = .
            (105,254 missing values generated)
            
            .                                 g ub_99 = .
            (105,254 missing values generated)
            
            .                                 
            .                                 parallel, prog(savereg): savereg
            invalid '16' 
                             stata():  3598  Stata returned error
            parallel_export_programs():     -  function returned error
                 parallel_write_do():     -  function returned error
                             <istmt>:     -  function returned error
            r(3598);
            
            end of do-file
            
            r(3598);
            without the comma: parallel prog(savereg): savereg

            Code:
            .                                 
            .                                 parallel prog(savereg): savereg
            --------------------------------------------------------------------------------
            Parallel Computing with Stata (by GVY)
            Clusters   : 4
            pll_id     : is7mlmzo23
            Running at : C:\Stata 16 MP
            Randtype   : datetime
            Waiting for the clusters to finish...
              0
            cluster 0004 Exited with error -199- while running the command/dofile (view log)...
            cluster 0001 Exited with error -199- while running the command/dofile (view log)...
            cluster 0002 Exited with error -199- while running the command/dofile (view log)...
            cluster 0003 Exited with error -199- while running the command/dofile (view log)...
            --------------------------------------------------------------------------------
            Enter -parallel printlog #- to checkout logfiles.
            --------------------------------------------------------------------------------
            and here is the log of erreur:
            Code:
            . parallel printlog 1, e(is7mlmzo23)
            --------------------------------------------------------------------------------
            beginning of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__pllis7mlmzo23_do0001.log-
            --------------------------------------------------------------------------------
            
            
            running C:\Stata 16 MP\ado\base\profile.do ...
            
            
            . capture {
            -------------------------------------------------------------------------------
            > -
            Parallel computing with stata (by GVY)
            -------------------------------------------------------------------------------
            > -
            cmd/dofile   : "savereg"
            pll_id       : is7mlmzo23
            pll_instance : 1/4
            tmpdir       : C:\Users\LUCIEN~1\AppData\Local\Temp/__pllis7mlmzo23_tmpdir0001/
            date-time    : 15:14:49 26 Dec 2021
            seed         : XAA0000000000010e6850d2f92cc8dd204939d0df762bca64aad1aa341029760
            > 7e5bd82f2e1b8887d725ea8659768689cb5c6d1e775e4e4d7aa7a8b52337493bfbcba5989047f
            > 187741af3b6043c87633d0e4c5947561b649f4b766bd94fc7f897616eac8e1181fb5709e0b138
            > ad2c574bdb56e2b1fa8cb46a1d7eda73d04a547b6904d8f5547f965e13684b401118185f8ab5e
            > bc9fee9294aad1c020720d4b799bec73ad63ad0ec7cc584775ae8033d078bea93a977ff4ac5b5
            > e6ab1539b4f72bcda9ef0459ae3ee51dacaa1e75b05928390ba9e0f0828409af71f2b031f96c2
            > d34001bf5d7b356eac52d8eeebf0fd478617f0bf68b8948bd902168a18f4ca3c44902c93609f0
            > 65414129d066390a1b1fff66b0907f124caf54441f2efcd55b7611ddd5c38d8e9dc04a23893bc
            > 6395a8d95afd3c400b8a53a56a08292705430ffb0f3da730b638d51a998eb9dff9d75bbb45a59
            > 6691008e6af3a1eedac2746dec1470a310d024be7191293716daff487658c416cd806efe7ef53
            > 81388f952b57d840a321b14680185595c844ae0979f2f5008c42d1e7bb3e9dde09fd06ad5ae4c
            > ce530306430f7e997c85d6e8e7b987b39347f43e34fb16f687c4a781ebffd2d7f994e5da93b68
            > 815e2f26729ee417616528b60e5c5d3639fbf2c51f5f8c62b65a24d0cfac339d34e10a81649fa
            > 2d2eaca5fb011cee11f7bc00794d8098442802c0ceae2c6e6e25bfce64c79db3b182f8dba8b75
            > 02387dce38c3a66e0e972e067564cfd80332f9ad02366e9f0f6976e6cc9e0f4b9c6b21c62286f
            > 198be66d9b3e737c8afdcc4cc3a89207a79c3a6ad415ed9cafed933981fd076ae71dab3564562
            > 554d0ea019354fb3e91e28a01b82509787587e9352059652e70167866d1d1c5ffd7eb54b70bba
            > 07c6bb9de5d038537a418d3e028140ea353863b1f977ce7e2eacdc141b3ef5bfb1c8eae1fe911
            > ca85c82767c2e56f8abad82764e7d94dcc004fce7ac08182fe3f3b4b034c5793a5e531580d16a
            > ce5cc19ca5e181e86ecd33e0ab5f83e81cd505d4b5a48b6f8ece49d3225eaa4f8b0daef559fd4
            > 63df3bb03d50ebe64c0bf52075caea81e3e66b206bb6bd6ecb4f567aba3314ba4c2b00760a00e
            > 9faca7575b5c26419a9aca6965745803a269ecb2c51b7e60c644e49a5766dd54d5a1501ff46f9
            > d9ee282071a0241361bda5cd656bff06a477d25ffda6be859905a6ad93b53be4240f8c77ca0aa
            > 8f6c174d4fb539c721f5b6da5e2dc14ff2941e373481c489100b040d5b90a3d04ece8a2d54e3a
            > 3b023c6797a0877e9e23b934c0f94dfa599758f24b72514f24ff31d2d396b7adbe626f8dd8d17
            > 75c624b0e6d1ebcaf4e91601bce22992b55929615af872a8d50cbfea13d558da38cbb6b998e85
            > 1ae2112752ef9f262b848720d402169d01b6ebb11b485c3b51932db1685b054a4b8aae6a687b6
            > 15b840ac2d8725061224a18e609d7c162d170ad8869e69cbd89c7ecaba7e1cfea61902e646add
            > a44da32249cdedb395e2265ba4839b4b78e7ec046c99afb1da23ee8d3c12921938296710327a5
            > 9bdb5ec7a79fe1d228a8e34f262df6f4fc04add0c16c14ce5274b93ed218f5866f5366519418e
            > 6ab0752a7da14d0f12fb6d7b8968b11be6ae6fad002cdd639f0e09e8bf21177d5c8d5fab26291
            > ff09334d6f042a7fd051e5962fa2fb74d3b77c8b34d7f5f4daef570b6a29027b21e1c15258315
            > 5e0bb9dddad8764a62e4a5daf86300c9601681b99b325bc3a91b324543495fb6f51387505e241
            > f41f04f92bc41453d3821edba51f9e308fe27f6efd63234974696899061be0851ef7ba63c4793
            > 0bfa4b6e83c5d06f57b5a5d41a42ad7dfb4a7821270afcacb61d442d12d3bbed1be19adcc62ae
            > f89740eb998a5b4e986f6dd5af71246de256b912167c54b4881b261a4e45d13e71bd505ac653e
            > 62ddd51ed16f0f3b472b4d566303a764ea2df80ce535c272e25bbcfd945a9a1e7c28c8f83b553
            > 1131341d6b597fc617bd43319fdbbfecaf7333191488d86028d5468625edc153cc2bd63ae141b
            > 669bce10a5cd7e6ba4445674cec63e46e54900c210b0d192ccdd3cb83f59fb81c2fd9c9d9b67e
            > 98ea786eb00fad7456f8f1fd78534129c8f8520318d7ef521361e777b7e97f82566045405dfc0
            > 09186aa0e05e566f91e59e0dfe26c104b4ebbb373b5604802492b4e652c63830c765e731e5c1c
            > 5e0698a743480ae7e8f3500b77097964162497bcdd0a6401cce79185cb175f51c887774193f68
            > 373d36b10432af8d8eeb815a273b60f9828826f7650f050d989dea25b59eda75f37d0de79d131
            > f3a0445b7ab8e3f14fd9f9a6d5ff003534977548f9c6545e06f89f012336ce85e30e2e2c884b6
            > fa856384b55665db05340c0b790e52ee3625fe3727e24044e05693108e4844de9ac74bfb01021
            > a91f07889df9c26f4604d1d6b3cb379d23af04c38c878e2ea6371630cbe0e1beb5a0c42c9ec1b
            > 50c552e67656e45b52adff8e6ea5060b6438301b61d09be10612a9ee4620e98718bf3c1e015db
            > a674b3308c60e8cfde2140d874285065f1571475aab9ef9f82cce51098daaa72a35ca9b51be9a
            > 8d43038be963e99e78d7494ddf407553d0e85f33d9424e52d0ae8ff9b6a6f4266a6e3eaa04004
            > 66b074f2d914aacf78d0038ce88e04777b5b39f8546494bd6bee24f67a74d4803fa3eed9a9c8b
            > 8e3ab4f0eb2b99b1e39e94532dd25f5292ca7c8ec3a43e4d029bebb0c6dbeabf6affe875474e9
            > c25f613164269b536b01cc500e0bc9c63305f2123323f6a4279c7b39759c25030d5157b830b3f
            > 565097b634d32409f140720af7115496a49f5563ddf8be24ad29ab998cc1dc672ce428517c444
            > 56940e8ec4d12796f8aff9b258dc8170046fcb0ecfd16de4bb1dfc96e0b28074d33616df44f04
            > 10cc093eb68ecd2700299453727929598b44a97a503197b37473993ed628ca9797496bca2a6f1
            > e106564796186ac9e7e9c0f905fbe460d25a202daeb7fd544fc84a3999f97df39e03f440b0f6a
            > 92ebaec531419821a734f581a059963fda2f27bb7ee86338c9abc39477bf6141baf14d4167f0b
            > 9ec87fd5551fbbfa0e0fc6ab022e072e4f49b5655e0212017b583e7b6fba5c32da72798b034f7
            > e0c4b34cafc494e943d1c4ed4f78a22cf0f0b62585146536b5dee5784bb1da339d8d30ee6b6a6
            > c067c64fa33894a1729e9927e1e4670274bbdbc561eb810f86d58aa5183b383e33462ea070f85
            > 4dd9987ec2c8975a57455820ad514c80919cbed1bae697377cbb59dafc649f4db4a886e2e848d
            > fa599d938fa185107e6b1a4254a18ffea2196fab7ca6a73e94f911922f3df40f4afe7e7ce1d0a
            > a3d46a5dc443d782e7c40b36257ce23fec38c8617fa7d7316989eca65246240f2631aaed3db4f
            > 926d06aa878baa5e9e7c9369881877fc3260c1f78c09110e6f78143914a81420c24999d9518df
            > 87a2965d0bc18239a1a101d960f62a93e13f5db6fcc86bb2470e834e16acbe535594e96ecc822
            > 3a100010000013848fb
            -------------------------------------------------------------------------------
            > -
            
            . local result = _rc
            
            . if (c(rc)) {
            . cd "C:\Stata 16 MP/"
            . mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllis7mlm
            > zo23_finito0001","while setting memory")
            . clear
            . exit
            . }
            
            . 
            . /* Checking for break */
            . mata: parallel_break()
            
            . 
            . /* Loading Globals */
            . capture {
            
            . if (c(rc)) {
            .   cd "C:\Stata 16 MP/"
            .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllis7m
            > lmzo23_finito0001","while loading globals")
            .   clear
            .   exit
            . }
            
            . 
            . /* Checking for break */
            . mata: parallel_break()
            
            . capture {
            .     use "C:\Stata 16 MP/__pllis7mlmzo23_dataset" if _is7mlmzo23cut == 1
            . 
            . /* Checking for break */
            . mata: parallel_break()
            .     savereg
            command savereg is unrecognized
            r(199);
            .   }
            
            . if (c(rc)) {
            .   cd "C:\Stata 16 MP/"
            C:\Stata 16 MP
            .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__pllis7m
            > lmzo23_finito0001","while running the command/dofile")
            .   clear
            .   exit
            
            end of do-file
            --------------------------------------------------------------------------------
             end of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__pllis7mlmzo23_do0001.log-  
            --------------------------------------------------------------------------------
            
            .
            Sorry to be so long but it's so we can understand each other.
            Thank you very much

            Comment


            • #7
              Hi Lucien,
              Thanks for this - the more detail the better.
              Does the program loop work outside of parallel?
              If so, then obviously the problem relates in some way to parallel - its syntax and structure.
              I note that your call to parallel is placed within a restore and preserve loop of sorts. I'm not sure how this affects parallel, but try executing parallel outside. That is, initialise parallel and define the program as you you have done, then simply execute parallel on its own, directly after the - end - clause of program define.
              Again, include the log output.
              Matt

              Comment


              • #8
                Hello Mathiew
                Thanks
                Does the program loop work outside of parallel?
                When I run the program without parallelization, yes it works fine. Here is the code and see the result (graph). As it takes a long time to run, I reduced the number of iterations to 3.
                Code:
                          
                            
                            preserve
                                
                                *drop beta se i_pos lb_* ub_*
                                g i_pos = .
                                g beta = .
                                g se = .
                                g lb_90 = .
                                g lb_95 = .
                                g lb_99 = .
                                g ub_90 = .
                                g ub_95 = .
                                g ub_99 = .
                                
                                qui {
                                    sum rp_partner_rank, d
                                    
                                    forvalues i = `r(min)' (1) 3 {
                                            
                                                xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_all $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
                                                *eststo
                                                lincom _b[lag_fdi_in_all], l(95)
                                                replace beta = r(estimate) in `i'
                                                replace se = r(se) in `i'
                                                replace i_pos = `i' in `i'
                                                replace lb_95 = r(lb) in `i'
                                                replace ub_95 = r(ub) in `i'
                                                
                                                lincom _b[lag_fdi_in_all], l(90)
                                                replace lb_90 = r(lb) in `i'
                                                replace ub_90 = r(ub) in `i'
                                                
                                                lincom _b[lag_fdi_in_all], l(99)
                                                replace lb_99 = r(lb) in `i'
                                                replace ub_99 = r(ub) in `i'
                                            
                                    
                                    }
                                }
                            
                                
                                twoway rarea ub_90 lb_90 i_pos , astyle(ci) || ///
                                line beta i_pos
                
                                save "$DataCreated\asup", replace
                            restore
                Click image for larger version

Name:	Graph.png
Views:	1
Size:	54.4 KB
ID:	1642393




                If so, then obviously the problem relates in some way to parallel - its syntax and structure.
                I note that your call to parallel is placed within a restore and preserve loop of sorts. I'm not sure how this affects parallel, but try executing parallel outside. That is, initialise parallel and define the program as you you have done, then simply execute parallel on its own, directly after the - end - clause of program define.
                Here is what I tried to do to answer this point.

                without the comma: parallel prog(savereg): savereg

                Code:
                . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
                
                .                         g i_pos = .
                (105,254 missing values generated)
                
                .                                 g beta = .
                (105,254 missing values generated)
                
                .                                 g se = .
                (105,254 missing values generated)
                
                .                                 g lb_90 = .
                (105,254 missing values generated)
                
                .                                 g lb_95 = .
                (105,254 missing values generated)
                
                .                                 g lb_99 = .
                (105,254 missing values generated)
                
                .                                 g ub_90 = .
                (105,254 missing values generated)
                
                .                                 g ub_95 = .
                (105,254 missing values generated)
                
                .                                 g ub_99 = .
                (105,254 missing values generated)
                
                .                        
                .                         parallel setclusters 4
                N Clusters: 4
                Stata dir:  C:\Stata 16 MP/StataMP-64.exe
                
                .                         capture program drop savereg
                
                .                         program define savereg
                  1.                                 qui {
                  2.                                         sum rp_partner_rank, d
                  3.                                        
                .                                         forvalues i = `r(min)' (1) 10 {
                  4.                                                        
                .                                                                 xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_al
                > l $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
                  5.                                                                 *eststo
                .                                                                 lincom _b[lag_fdi_in_all], l(95)
                  6.                                                                 replace beta = r(estimate) in `i'
                  7.                                                                 replace se = r(se) in `i'
                  8.                                                                 replace i_pos = `i' in `i'
                  9.                                                                 replace lb_95 = r(lb) in `i'
                 10.                                                                 replace ub_95 = r(ub) in `i'
                 11.                                                                
                .                                                                 lincom _b[lag_fdi_in_all], l(90)
                 12.                                                                 replace lb_90 = r(lb) in `i'
                 13.                                                                 replace ub_90 = r(ub) in `i'
                 14.                                                                
                .                                                                 lincom _b[lag_fdi_in_all], l(99)
                 15.                                                                 replace lb_99 = r(lb) in `i'
                 16.                                                                 replace ub_99 = r(ub) in `i'
                 17.                                                        
                .                                        
                .                                         }
                 18.                                 }
                 19.                        
                .                         end
                
                .                        
                .                         parallel prog(savereg): savereg
                --------------------------------------------------------------------------------
                Parallel Computing with Stata (by GVY)
                Clusters   : 4
                pll_id     : tggc8rbz55
                Running at : C:\Stata 16 MP
                Randtype   : datetime
                Waiting for the clusters to finish...
                cluster 0002 Exited with error -199- while running the command/dofile (view log)...
                cluster 0003 Exited with error -199- while running the command/dofile (view log)...
                cluster 0004 Exited with error -199- while running the command/dofile (view log)...
                cluster 0001 Exited with error -199- while running the command/dofile (view log)...
                --------------------------------------------------------------------------------
                Enter -parallel printlog #- to checkout logfiles.
                --------------------------------------------------------------------------------
                the log output

                Code:
                . parallel printlog 1, e(tggc8rbz55)
                --------------------------------------------------------------------------------
                beginning of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__plltggc8rbz55_do0001.log-
                --------------------------------------------------------------------------------
                
                
                running C:\Stata 16 MP\ado\base\profile.do ...
                
                
                . capture {
                -------------------------------------------------------------------------------
                > -
                Parallel computing with stata (by GVY)
                -------------------------------------------------------------------------------
                > -
                cmd/dofile   : "savereg"
                pll_id       : tggc8rbz55
                pll_instance : 1/4
                tmpdir       : C:\Users\LUCIEN~1\AppData\Local\Temp/__plltggc8rbz55_tmpdir0001/
                date-time    : 16:32:14 26 Dec 2021
                seed         : XAA0000000000006cd05599811d4b1e509122105c49e21b995280b7c72704a3a
                > 16d4df0d0d5e7747187df36c8744ec76e930727adbce2b7df5678cf041d972bec25a4b740317d
                > d25e5cb6e1b4194f81388ff4952eacdad5e3d3657f1ea1ebad3b9b23bc91f8c6a6e01ed7c53a3
                > 70dfa47531104c483dfef391ea48bf4bd30d8ec55fe8d2c339603b45b08b059a74c565b89a548
                > 7dcc35540e278acd29fa4a53d794ab4f9009aafe4f725eafd9d0b44c86c543e1fc224862ec8a9
                > b12e42bbda3898682dab7fab0cba84c4401fefc39b147cfe08f1fab09aed150c5cbdb59e6e1f8
                > b2c1480acefb1d86392485613021895e4f43a922ef62e9c501bb9d7fb204d2a11fd5d70f34b8d
                > 4b5394960b0c2b60da153c6292fc80027098cdd9d45ed68d59f464ed3447c96b93a455cfb9dbb
                > 7c0afa1948520758eff7de5e88a54da9c72e37da9d3a381a918bf920928e82481efca923d1e9e
                > 81e068619f700316e2937769c0f3e2208c2dfffdfcffc0b3123077d0890969e1c07f9ca6f05fc
                > 1e8e5608bcfd6acda08424f50ca2a54dccbfe24a86f15f838873786f2c0fb839f4e054c5ce09e
                > 56780ca24ba695875ae2aa2e5f2ea1899bbe7a6bb2b9238755b7b474d63f9f6227160f2e93a6a
                > a15feaed0477fe81ffbf495c2dfbe3243846d486903aba9c1db6b6d02f664687040de3ec36643
                > 17a27e06dd2b2ffe761a025c0a88875ff8f029378036cd51c38e3906fc95f9eae49efbeeedf1c
                > 238f19e5d5baaeef2a4e2090e101dbff109bb9152b1c6b5cbd47100dd47838d23d71129a8a372
                > a6c0951d71fb6696627da9879dd46ac03f12b20851ec4c2785d2272e8a318266bcfa18e86110a
                > b644ecf372d6f50e259897bc0356076975ecce6ebfe964c3fde9d587c1ecf469edc5182d5d998
                > cf25b694bfc352e55ae2ef80ae22881e11521a9d2f4cab6fc04c6cbf19e47844908496c36e9f9
                > e44c44634a1ebf0f20a377e3d8e25b0582461549b11d3aeb793c3639f06b47e931df04b529144
                > 3b8bb300e560721dedcb9667706e180be71198d1a5e221aea669fb3efb81da151a5dbb3340483
                > 97337bf44adda62096cd29b5cc398e9dab91e79d2bc0833a9b1ebf3fef7c334d01be22629b890
                > 432d621293b4e79a135d15e43c7d2aaa7607e9187695feee046570cf877f0e30b67cd3cdff477
                > c80d66e1cebccd469135b4b0eb247c56e7afff5935416ae006f720183a173f5d20b05b266d1eb
                > 6bc94c80b222158fb90ccd773c4cd2d8a25d23f60c00798b0552d7c709ae940714c5ae7053e93
                > fdc29171d456195da0b51f7dc1a4d819d6cc0b9ac452443327abf15a0443c10b2ac1941b329a9
                > 88ec4376e36861424e92ad929f6eea581fc1f006c5d03a0bca3a38baf0001fbc226e65ec37bbe
                > 7f3ceecc39621b30b52634e24da5e2540648baf17b4738cb458592fb2dcc84864ecf8cfe16ed3
                > b887b26a007e3fa8664e84d4f7b2e85b6c88b7405e3064aaeb5ea55e6d9d7f3ed38ec33c55b14
                > 728864e5d8af30919a6e39316ffe9bd0370a0bebb456afb9a34aa73353f1fdb56a8bdd9ca2b34
                > 67ab19fbbb9e409f1799cf722c6c5fcddd7229dfeadf5977a5df9269b997f7f1fa7270f2755c7
                > 37135250d873911c25694b5e8824345cd397e295a6427c7b077cafa8c05a13ad6f93ed6980ad7
                > 6eb2d7c278b417aca3eb96308b85c7ba645dfa61f8befa499ba76f37cab6d107a72ab6191341b
                > 93daf74187168e58348418be81f7ac6c5002474a21eee397ec5bf3d678336bfaa760cb1567878
                > 2629a6a3892ce5f8b7e736cf600ac2a096b7898f26c10c13e421d88260af0da2f682b1e87c10b
                > 66edeadf59ad430250e8c5b923b3edcef1257224e4f89f0c26255585f2943605b2bb971da7383
                > b1532e4d85460be6e4b3162a03e9f6803eb5135f6324e40f5173986e894a070eb0411cf7361d1
                > 4324d5cf8689b8be672d36601e9529f10c7ddff54a39d537300d2d1d53b4037315c9883280db5
                > 6c1752302444c303d4ba6432c52b44fd76ce45937f7e3969d99967b8232ece5f0076fe09ced3e
                > 50a37eed8231ee224d5b4b6c5455dc399a0e3c17f1e38105f7d24965aacc669624e0ea9790cb3
                > 8be95ca1f123e54d3eb19498885bf99043a4ee99b6c3f62a671a0f557a3587180d765e6d5fbb8
                > 84df77ad0cbd588887ed5c5623f7131ceb95e5df46b047a4c52e09f50ec0146cbb0bcca755af0
                > be26cccd31f7f7840f08532ff0b6b19c3831f4ecb886d5362f2ba8fbedc65844264cd9530a1bf
                > 15ac19f378ece902ff5d5f72913b19bf8ac7150165cb305f2ed2bedacc86962bd45fa2169b925
                > 8a6802a2b742a624693da400fd3c702c35ee6e46adaae3bbded0fda7574aec4dd3ec4aab8b398
                > bdd84438c2caf6bf87cb1c00ce62649a1556834b1b5612b96af38031f37310ea5c33881e35017
                > 1738474b6051cd660b2d396389c0b90cb899dddf172933c8a2263b30d2ccbb79cefd6cb8b82af
                > 2cd9de778be10b7c04e824faf231402469c142ac3b5ccfa6c5ce808c3ef8df7fbe66d6e8f39db
                > e43e985060311968aa4cacba3f83943b2a52c224ee84285a9026f401711abb80df3ba292df29a
                > 705552a25ae50d9ea106e9f0bd9046dadde50b5541399ce0965a4a5ac01431d06714cbb31f7df
                > 0d42a63bc596b96015c0aba8bf96e96e218fcda1fde02a7a72552f6a83934823c9c5a09787fba
                > 578b8804d6195b12597f054b0bfaca09a7cfd2035264c38c6836095ba3754e805cf7885e58f72
                > 86de17b097ad5a5c92853995db5d3deb922529a2231391607379af897faa071652b739c83083a
                > 3e971476037964a2d5b215e4a43fc5237ee646c1a1e163111310cfe293b61d7b56fb3f9ec128f
                > 29e2b803d02cd067c9e692eed1c85e0368a3ac68c63288dcd637f15549d14ca061708a791e95f
                > 576f9c8a44bdf4ec4eebcb83e9e343bbe7f4f1f12398d2241983d181aad7fb3f98cb38ce5d585
                > 99519c101973678d91c9ab7b540470466eeee4ee095fdf5fb14866d2457a1d2e495c6ff8f4a8e
                > b94f0e0781c782e5232d73c129d6dbd3ffea175588786056ee3246003675d5d826bb4d6aed5a9
                > bd7410632b327ea86b041ac3a02d25292605737316d1eb73456233f436a94ae1c18494270b727
                > ccad8f2bf09be7d86f1de5681601b253452d62beba1c3565d1becfb4f8c23da9fd18491501e9a
                > 61639b39250b26eefff10638d3981121f515837c5fdf814097c0aa389bf337e864a4c9154e065
                > 37dab3e5dc3b2ef7779f583b8ad84037eaba320028f92a1e0901e90ec705d7541550240607b59
                > daaedbbdc32fd1364d29004733c49f81689cb6183d15a3e30fd61078be7456443948a0964a91e
                > 852dfeba183e195e2130a61e8fd97d4fdd3397514e0929683850bf7eb58d6de4d8acde11fe433
                > 09bbbd5a12e7a7f1a273b14fb31ceb6cd0b2bbf587393b16dcfe4d34640ae48c1315bb18ab36e
                > eb0c03b468009cb6a890ed0087325805a275b3d40d97f370002c47c54ed55a401c6796033a869
                > e770001000001380bd1
                -------------------------------------------------------------------------------
                > -
                
                . local result = _rc
                
                . if (c(rc)) {
                . cd "C:\Stata 16 MP/"
                . mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__plltggc8r
                > bz55_finito0001","while setting memory")
                . clear
                . exit
                . }
                
                .
                . /* Checking for break */
                . mata: parallel_break()
                
                .
                . /* Loading Globals */
                . capture {
                
                . if (c(rc)) {
                .   cd "C:\Stata 16 MP/"
                .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__plltggc
                > 8rbz55_finito0001","while loading globals")
                .   clear
                .   exit
                . }
                
                .
                . /* Checking for break */
                . mata: parallel_break()
                
                . capture {
                .     use "C:\Stata 16 MP/__plltggc8rbz55_dataset" if _tggc8rbz55cut == 1
                .
                . /* Checking for break */
                . mata: parallel_break()
                .     savereg
                command savereg is unrecognized
                r(199);
                .   }
                
                . if (c(rc)) {
                .   cd "C:\Stata 16 MP/"
                C:\Stata 16 MP
                .   mata: parallel_write_diagnosis(strofreal(c("rc")),"C:\Stata 16 MP/__plltggc
                > 8rbz55_finito0001","while running the command/dofile")
                .   clear
                .   exit
                
                end of do-file
                --------------------------------------------------------------------------------
                 end of file -C:\Users\LUCIEN~1\AppData\Local\Temp/__plltggc8rbz55_do0001.log-  
                --------------------------------------------------------------------------------

                with the comma: parallel, prog(savereg): savereg
                Code:
                . drop beta se i_pos lb_* ub_*
                
                . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
                
                .                        
                .                         g i_pos = .
                (105,254 missing values generated)
                
                .                                 g beta = .
                (105,254 missing values generated)
                
                .                                 g se = .
                (105,254 missing values generated)
                
                .                                 g lb_90 = .
                (105,254 missing values generated)
                
                .                                 g lb_95 = .
                (105,254 missing values generated)
                
                .                                 g lb_99 = .
                (105,254 missing values generated)
                
                .                                 g ub_90 = .
                (105,254 missing values generated)
                
                .                                 g ub_95 = .
                (105,254 missing values generated)
                
                .                                 g ub_99 = .
                (105,254 missing values generated)
                
                .                        
                .                         parallel setclusters 4
                N Clusters: 4
                Stata dir:  C:\Stata 16 MP/StataMP-64.exe
                
                .                         capture program drop savereg
                
                .                         program define savereg
                  1.                                 qui {
                  2.                                         sum rp_partner_rank, d
                  3.                                        
                .                                         forvalues i = `r(min)' (1) 10 {
                  4.                                                        
                .                                                                 xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_al
                > l $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
                  5.                                                                 *eststo
                .                                                                 lincom _b[lag_fdi_in_all], l(95)
                  6.                                                                 replace beta = r(estimate) in `i'
                  7.                                                                 replace se = r(se) in `i'
                  8.                                                                 replace i_pos = `i' in `i'
                  9.                                                                 replace lb_95 = r(lb) in `i'
                 10.                                                                 replace ub_95 = r(ub) in `i'
                 11.                                                                
                .                                                                 lincom _b[lag_fdi_in_all], l(90)
                 12.                                                                 replace lb_90 = r(lb) in `i'
                 13.                                                                 replace ub_90 = r(ub) in `i'
                 14.                                                                
                .                                                                 lincom _b[lag_fdi_in_all], l(99)
                 15.                                                                 replace lb_99 = r(lb) in `i'
                 16.                                                                 replace ub_99 = r(ub) in `i'
                 17.                                                        
                .                                        
                .                                         }
                 18.                                 }
                 19.                        
                .                         end
                
                .                        
                .                         parallel, prog(savereg): savereg
                invalid '16'
                                 stata():  3598  Stata returned error
                parallel_export_programs():     -  function returned error
                     parallel_write_do():     -  function returned error
                                 <istmt>:     -  function returned error
                r(3598);
                
                end of do-file
                
                r(3598);
                
                .
                A very strange thing I noticed when I run with the comma (parallel, prog(savereg): savereg), is that all the data (variables) in the database is deleted. There are no more observations.
                Thanks again.
                Last edited by Lucien AHOUANGBE; 26 Dec 2021, 09:57.

                Comment


                • #9
                  for your post: #5
                  Yes I thought of that when the data was deleted and there was no more observation, but only the single loop works. The parallelization codes return the same errors.
                  Thanks

                  Comment


                  • #10
                    Hi Lucien,
                    My next suggestion is to set parallel path. Note the error message "invalid `16'" - it may result from the use of / instead of \ in the path name.
                    Replace parallel setclusters 4 with this exact code
                    Code:
                    parallel initialise 4, force s("C:\Stata 16 MP\StataMP-64.exe")
                    Run this code with the workaround that you sent above - that is, outside of the restore-preserve loop
                    Let me know,
                    Matt

                    Comment


                    • #11
                      Hi Matthiew,
                      It refuses to run. I verified if it is the good path to my STATA setup. and the path is good.
                      Code:
                      . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
                      
                      .                         parallel initialise 4, force s("C:\Stata 16 MP\StataMP-64.exe")
                      something required
                      r(100);
                      
                      end of do-file
                      
                      r(100);
                      
                      . do "C:\Users\LUCIEN~1\AppData\Local\Temp\STD210_000000.tmp"
                      
                      .                         parallel initialise 4, force s("C:/Stata 16 MP/StataMP-64.exe")
                      something required
                      r(100);
                      
                      end of do-file
                      
                      r(100);
                      
                      .
                      Thank you

                      Comment


                      • #12
                        Hi Lucien,
                        That's my fault - I misspelt initialize....so code is

                        Code:
                        parallel initialize 4, force s("C:\Stata 16 MP\StataMP-64.exe")
                        Matt

                        Comment


                        • #13
                          I just tried another idea to understand just the function of the parallel command
                          I created a do file named "savereg.do" with this code. I saved all my necessary variables in a database named "asup2.dta" in advance

                          here is the code in the do file:

                          Code:
                          qui {
                                              
                                              sum rp_partner_rank, d
                                              
                                              
                                              forvalues i = `r(min)' (1) 10 {
                                                          use "$DataCreated\asup2", clear
                                                          xi: reg rp_avg_pc_epi_gap_abs lag_fdi_in_all $contrlsorder i.year i.pccountry i.rpcountry if rp_partner_rank <= `i', vce(cl id)
                                                          *eststo
                                                          lincom _b[lag_fdi_in_all], l(95)
                                                          replace beta = r(estimate) in `i'
                                                          replace se = r(se) in `i'
                                                          replace i_pos = `i' in `i'
                                                          replace lb_95 = r(lb) in `i'
                                                          replace ub_95 = r(ub) in `i'
                                                          
                                                          lincom _b[lag_fdi_in_all], l(90)
                                                          replace lb_90 = r(lb) in `i'
                                                          replace ub_90 = r(ub) in `i'
                                                          
                                                          lincom _b[lag_fdi_in_all], l(99)
                                                          replace lb_99 = r(lb) in `i'
                                                          replace ub_99 = r(ub) in `i'
                                                      
                                              
                                              }
                                          }
                          Here is the output. it runs:
                          Code:
                          .                         
                          .                         preserve
                          
                          .                                 parallel do "$Code\saveregdo.do"
                          --------------------------------------------------------------------------------
                          Parallel Computing with Stata (by GVY)
                          Clusters   : 4
                          pll_id     : a6pogutk69
                          Running at : G:\Etude et biblio\Université\tours\Master2 IE\Econometrie avancee\memoire\donnees\Code
                          Randtype   : datetime
                          Waiting for the clusters to finish...
                          cluster 0002 has exited without error...
                          cluster 0001 has exited without error...
                            0
                          cluster 0003 has exited without error...
                            0
                          cluster 0004 has exited without error...
                          --------------------------------------------------------------------------------
                          Enter -parallel printlog #- to checkout logfiles.
                          --------------------------------------------------------------------------------
                          
                          .                                 twoway rarea ub_90 lb_90 i_pos , astyle(ci) || ///
                          >                                 line beta i_pos
                          
                          .                         restore
                          
                          . 
                          end of do-file

                          But the result is not what I always expect.

                          Click image for larger version

Name:	Graph2.png
Views:	1
Size:	37.2 KB
ID:	1642399

                          Maybe it's an explorable track too
                          Thanks Matthiew

                          Comment


                          • #14
                            Hi Lucien,
                            Glad you found some form of solution!
                            What do you mean by "the result is not what I always expect"?
                            If you're still encountering issues, try the parallel initialize force method above.
                            I'm quite certain that should work. In any case, you should be able to achieve what you want with the do-file. So stick with that if the program method is still causing problems.
                            Best,
                            Matt
                            Last edited by Matthew Alexander; 26 Dec 2021, 10:52.

                            Comment


                            • #15

                              I don't know why but I have a problem with the term "initialize".

                              Code:
                              .                         parallel initialize 4, force s("C:\Stata 16 MP\StataMP-64.exe")
                              something required
                              r(100);
                              
                              end of do-file
                              
                              r(100);
                              
                              . parallel initialize 4
                              -initialize- invalid parallel subcommand (help parallel)
                              r(198);
                              
                              . h parallel
                              
                              . parallel initialize 2
                              -initialize- invalid parallel subcommand (help parallel)
                              r(198);
                              
                              . h parallel
                              The results are not what I expect, because even if the command works on stata, instead of showing me the graph with the coefficients it refuses. It seems that STATA does not calculate the coefficients. I continue to search for the reason.

                              Comment

                              Working...
                              X