Announcement

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

  • Error in parallel

    Hi!
    Very new to stata. I'm trying to replicate/extend the findings of this paper
    The replication file is in there.


    Imagine I have this data (this is just some randomly generated data. The actual data is too heavy to post)
    * Generate random data similar to RegressionData.dta
    clear
    set seed 12345
    set obs 90000 // Adjust to create 9000 unique banks with multiple time periods

    * Simulate bank ID (rssdid) and time (date in quarterly format)
    gen rssdid = floor((runiform() * 9000)) + 100000
    gen date = tq(2000q1) + floor(runiform()*100)
    format date %tq

    * Drop duplicate combinations of bank ID and date
    duplicates drop rssdid date, force

    * Simulate interest income and expense rates
    gen s1_intincrate = runiform(0.01, 0.06)
    gen s1_intexprate = runiform(0.005, 0.05)

    * Simulate NIM
    gen s1_nim = s1_intincrate - s1_intexprate

    * Simulate current and lagged federal funds rate shocks
    gen s1_fedfunds = rnormal(0.02, 0.005)
    gen l1_s1_fedfunds = s1_fedfunds + rnormal(0, 0.001)
    gen l2_s1_fedfunds = l1_s1_fedfunds + rnormal(0, 0.001)
    gen l3_s1_fedfunds = l2_s1_fedfunds + rnormal(0, 0.001)

    * Simulate rank percentile and equity-to-assets ratio
    gen rankpctile = runiform()*100
    gen s1_equity_assets = runiform(0.05, 0.20)

    * Set panel structure
    xtset rssdid date

    * Optional: sort and compress
    sort rssdid date


    My idea is to extend some results, and I'd like to parallelize the bootstrap, because otherwise, it takes too long.

    [parallel setclusters 8
    capture program drop t2_v3
    program define t2_v3, rclass
    preserve
    * * * * *
    bsample, cluster(date)
    *sort rssdid date
    *xtset rssdid date

    // No time fixed effects
    reghdfe s1_intexprate, absorb(i.rssdid i.rssdid#(c.s1_fedfunds c.l1_s1_fedfunds c.l2_s1_fedfunds c.l3_s1_fedfunds), save)
    gen expbeta1 = __hdfe2__Slope1 + __hdfe2__Slope2 + __hdfe2__Slope3 + __hdfe2__Slope4
    drop __hdfe1__-__hdfe2__Slope4

    reghdfe s1_intincrate, absorb(i.rssdid i.rssdid#(c.s1_fedfunds c.l1_s1_fedfunds c.l2_s1_fedfunds c.l3_s1_fedfunds), save)
    gen incbeta1 = __hdfe2__Slope1 + __hdfe2__Slope2 + __hdfe2__Slope3 + __hdfe2__Slope4
    drop __hdfe1__-__hdfe2__Slope4

    *reghdfe s1_equity_assets, absorb(i.rssdid i.rssdid#(c.s1_fedfunds c.l1_s1_fedfunds c.l2_s1_fedfunds c.l3_s1_fedfunds), save) --> for some reason, this does not work. the one below does
    reghdfe s1_equity_assets, absorb(i.rssdid i.rssdid#c.s1_fedfunds i.rssdid#c.l1_s1_fedfunds i.rssdid#c.l2_s1_fedfunds i.rssdid#c.l3_s1_fedfunds, save)
    gen equitybeta1 = __hdfe2__Slope1 + __hdfe3__Slope1 + __hdfe4__Slope1 + __hdfe5__Slope1
    drop __hdfe2__Slope1 __hdfe3__Slope1 __hdfe4__Slope1 __hdfe5__Slope1

    // With time fixed effects
    reghdfe s1_intexprate, absorb(i.rssdid i.rssdid#(c.s1_fedfunds c.l1_s1_fedfunds c.l2_s1_fedfunds c.l3_s1_fedfunds) i.date, save)
    gen expbeta2 = __hdfe2__Slope1 + __hdfe2__Slope2 + __hdfe2__Slope3 + __hdfe2__Slope4
    drop __hdfe1__-__hdfe2__Slope4

    reghdfe s1_intincrate, absorb(i.rssdid i.rssdid#(c.s1_fedfunds c.l1_s1_fedfunds c.l2_s1_fedfunds c.l3_s1_fedfunds) i.date, save)
    gen incbeta2 = __hdfe2__Slope1 + __hdfe2__Slope2 + __hdfe2__Slope3 + __hdfe2__Slope4
    drop __hdfe1__-__hdfe2__Slope4

    reghdfe s1_equity_assets, absorb(i.rssdid i.rssdid#c.s1_fedfunds i.rssdid#c.l1_s1_fedfunds i.rssdid#c.l2_s1_fedfunds i.rssdid#c.l3_s1_fedfunds i.date, save)
    gen equitybeta2 = __hdfe2__Slope1 + __hdfe3__Slope1 + __hdfe4__Slope1 + __hdfe5__Slope1
    drop __hdfe2__Slope1 __hdfe3__Slope1 __hdfe4__Slope1 __hdfe5__Slope1

    collapse incbeta1 expbeta1 incbeta2 expbeta2 equitybeta1 equitybeta2 rankpctile, by(rssdid)
    winsor2 *beta*, cuts(5 95) replace
    gen nimbeta1 = incbeta1 - expbeta1
    gen nimbeta2 = incbeta2 - expbeta2
    *pause
    *gen niibeta = incbeta2 - expbeta2
    // No time fixed effects
    reg incbeta1 expbeta1
    mat coef1 = e(b)
    return scalar expbeta1_coef = el(coef1, 1, 1)
    return scalar cons1_coef = el(coef1, 1, 2)
    mat coef2 = e(V)
    return scalar expbeta1_var = el(coef2, 1, 1)
    return scalar cons1_var = el(coef2, 2, 2)
    return scalar N1_100 = e(N)

    reg incbeta1 expbeta1 if rankpctile >= 91
    mat coef3 = e(b)
    return scalar expbeta1_coef_10 = el(coef3, 1, 1)
    return scalar cons1_coef_10 = el(coef3, 1, 2)
    mat coef4 = e(V)
    return scalar expbeta1_var_10 = el(coef4, 1, 1)
    return scalar cons1_var_10 = el(coef4, 2, 2)
    return scalar N1_10 = e(N)

    reg incbeta1 expbeta1 if rankpctile >= 96
    mat coef5 = e(b)
    return scalar expbeta1_coef_5 = el(coef5, 1, 1)
    return scalar cons1_coef_5 = el(coef5, 1, 2)
    mat coef6 = e(V)
    return scalar expbeta1_var_5 = el(coef6, 1, 1)
    return scalar cons1_var_5 = el(coef6, 2, 2)
    return scalar N1_5 = e(N)

    reg incbeta1 expbeta1 if rankpctile >= 100
    mat coef7 = e(b)
    return scalar expbeta1_coef_1 = el(coef7, 1, 1)
    return scalar cons1_coef_1 = el(coef7, 1, 2)
    mat coef8 = e(V)
    return scalar expbeta1_var_1 = el(coef8, 1, 1)
    return scalar cons1_var_1 = el(coef8, 2, 2)
    return scalar N1_1 = e(N)

    // With time fixed effects
    reg incbeta2 expbeta2
    mat coef9 = e(b)
    return scalar expbeta2_coef = el(coef9, 1, 1)
    return scalar cons2_coef = el(coef9, 1, 2)
    mat coef10 = e(V)
    return scalar expbeta2_var = el(coef10, 1, 1)
    return scalar cons2_var = el(coef10, 2, 2)
    return scalar N2_100 = e(N)

    reg incbeta2 expbeta2 if rankpctile >= 91
    mat coef11 = e(b)
    return scalar expbeta2_coef_10 = el(coef11, 1, 1)
    return scalar cons2_coef_10 = el(coef11, 1, 2)
    mat coef12 = e(V)
    return scalar expbeta2_var_10 = el(coef12, 1, 1)
    return scalar cons2_var_10 = el(coef12, 2, 2)
    return scalar N2_10 = e(N)

    reg incbeta2 expbeta2 if rankpctile >= 96
    mat coef13 = e(b)
    return scalar expbeta2_coef_5 = el(coef13, 1, 1)
    return scalar cons2_coef_5 = el(coef13, 1, 2)
    mat coef14 = e(V)
    return scalar expbeta2_var_5 = el(coef14, 1, 1)
    return scalar cons2_var_5 = el(coef14, 2, 2)
    return scalar N2_5 = e(N)

    reg incbeta2 expbeta2 if rankpctile >= 100
    mat coef15 = e(b)
    return scalar expbeta2_coef_1 = el(coef15, 1, 1)
    return scalar cons2_coef_1 = el(coef15, 1, 2)
    mat coef16 = e(V)
    return scalar expbeta2_var_1 = el(coef16, 1, 1)
    return scalar cons2_var_1 = el(coef16, 2, 2)
    return scalar N2_1 = e(N)

    // Now add the regressions of equity on nimbeta1
    reg equitybeta1 nimbeta1
    mat coef17 = e(b)
    return scalar nimbeta1_coef = el(coef17, 1, 1)
    return scalar cons3_coef = el(coef17, 1, 2)
    mat coef18 = e(V)
    return scalar nimbeta1_var = el(coef18, 1, 1)
    return scalar cons3_var = el(coef18, 2, 2)
    return scalar N3_100 = e(N)

    reg equitybeta1 nimbeta1 if rankpctile >= 91
    mat coef19 = e(b)
    return scalar nimbeta1_coef_10 = el(coef19, 1, 1)
    return scalar cons3_coef_10 = el(coef19, 1, 2)
    mat coef20 = e(V)
    return scalar nimbeta1_var_10 = el(coef20, 1, 1)
    return scalar cons3_var_10 = el(coef20, 2, 2)
    return scalar N3_10 = e(N)

    reg equitybeta1 nimbeta1 if rankpctile >= 96
    mat coef21 = e(b)
    return scalar nimbeta1_coef_5 = el(coef21, 1, 1)
    return scalar cons3_coef_5 = el(coef21, 1, 2)
    mat coef22 = e(V)
    return scalar nimbeta1_var_5 = el(coef22, 1, 1)
    return scalar cons3_var_5 = el(coef22, 2, 2)
    return scalar N3_5 = e(N)

    reg equitybeta1 nimbeta1 if rankpctile >= 100
    mat coef23 = e(b)
    return scalar nimbeta1_coef_1 = el(coef23, 1, 1)
    return scalar cons3_coef_1 = el(coef23, 1, 2)
    mat coef24 = e(V)
    return scalar nimbeta1_var_1 = el(coef24, 1, 1)
    return scalar cons3_var_1 = el(coef24, 2, 2)
    return scalar N3_1 = e(N)

    // Now the same, but with time fixed effects
    reg equitybeta2 nimbeta2
    mat coef25 = e(b)
    return scalar nimbeta2_coef = el(coef25, 1, 1)
    return scalar cons4_coef = el(coef25, 1, 2)
    mat coef25 = e(V)
    return scalar nimbeta2_var = el(coef25, 1, 1)
    return scalar cons4_var = el(coef25, 2, 2)
    return scalar N4_100 = e(N)

    reg equitybeta2 nimbeta2 if rankpctile >= 91
    mat coef26 = e(b)
    return scalar nimbeta2_coef_10 = el(coef26, 1, 1)
    return scalar cons4_coef_10 = el(coef26, 1, 2)
    mat coef27 = e(V)
    return scalar nimbeta2_var_10 = el(coef27, 1, 1)
    return scalar cons4_var_10 = el(coef27, 2, 2)
    return scalar N4_10 = e(N)

    reg equitybeta2 nimbeta2 if rankpctile >= 96
    mat coef28 = e(b)
    return scalar nimbeta2_coef_5 = el(coef28, 1, 1)
    return scalar cons4_coef_5 = el(coef28, 1, 2)
    mat coef29 = e(V)
    return scalar nimbeta2_var_5 = el(coef29, 1, 1)
    return scalar cons4_var_5 = el(coef29, 2, 2)
    return scalar N4_5 = e(N)

    reg equitybeta2 nimbeta2 if rankpctile >= 100
    mat coef30 = e(b)
    return scalar nimbeta2_coef_1 = el(coef30, 1, 1)
    return scalar cons4_coef_1 = el(coef30, 1, 2)
    mat coef31 = e(V)
    return scalar nimbeta2_var_1 = el(coef31, 1, 1)
    return scalar cons4_var_1 = el(coef31, 2, 2)
    return scalar N4_1 = e(N)


    * * * * *
    restore
    end

    * * * * * * * * * * * * * * *
    * B - Simulation
    * * * * * * * * * * * * * * *
    set seed 2020

    parallel bs reps(10): simulate, expbeta1 = r(expbeta1_coef) var1 = r(expbeta1_var) cons1 = r(cons1_coef) consvar1 = r(cons1_var) N1_100 = r(N1_100) ///
    expbeta1_10 = r(expbeta1_coef_10) var1_10 = r(expbeta1_var_10) cons1_10 = r(cons1_coef_10) consvar1_10 = r(cons1_var_10) N1_10 = r(N1_10) ///
    expbeta1_5 = r(expbeta1_coef_5) var1_5 = r(expbeta1_var_5) cons1_5 = r(cons1_coef_5) consvar1_5 = r(cons1_var_5) N1_5 = r(N1_5) ///
    expbeta1_1 = r(expbeta1_coef_1) var1_1 = r(expbeta1_var_1) cons1_1 = r(cons1_coef_1) consvar1_1 = r(cons1_var_1) N1_1 = r(N1_1) ///
    expbeta2 = r(expbeta2_coef) var2 = r(expbeta2_var) cons2 = r(cons2_coef) consvar2 = r(cons2_var) N2_100 = r(N2_100) ///
    expbeta2_10 = r(expbeta2_coef_10) var2_10 = r(expbeta2_var_10) cons2_10 = r(cons2_coef_10) consvar2_10 = r(cons2_var_10) N2_10 = r(N2_10) ///
    expbeta2_5 = r(expbeta2_coef_5) var2_5 = r(expbeta2_var_5) cons2_5 = r(cons2_coef_5) consvar2_5 = r(cons2_var_5) N2_5 = r(N2_5) ///
    expbeta2_1 = r(expbeta2_coef_1) var2_1 = r(expbeta2_var_1) cons2_1 = r(cons2_coef_1) consvar2_1 = r(cons2_var_1) N2_1 = r(N2_1) ///
    nimbeta1 = r(nimbeta1_coef) var3 = r(nimbeta1_var) cons3 = r(cons3_coef) consvar3 = r(cons3_var) N3_100 = r(N3_100) ///
    nimbeta1_10 = r(nimbeta1_coef_10) var3_10 = r(nimbeta1_var_10) cons3_10 = r(cons3_coef_10) consvar3_10 = r(cons3_var_10) N3_10 = r(N3_10) ///
    nimbeta1_5 = r(nimbeta1_coef_5) var3_5 = r(nimbeta1_var_5) cons3_5 = r(cons3_coef_5) consvar3_5 = r(cons3_var_5) N3_5 = r(N3_5) ///
    nimbeta1_1 = r(nimbeta1_coef_1) var3_1 = r(nimbeta1_var_1) cons3_1 = r(cons3_coef_1) consvar3_1 = r(cons3_var_1) N3_1 = r(N3_1) ///
    nimbeta2 = r(nimbeta2_coef) var4 = r(nimbeta2_var) cons4 = r(cons4_coef) consvar4 = r(cons4_var) N4_100 = r(N4_100) ///
    nimbeta2_10 = r(nimbeta2_coef_10) var4_10 = r(nimbeta2_var_10) cons4_10 = r(cons4_coef_10) consvar4_10 = r(cons4_var_10) N4_10 = r(N4_10) ///
    nimbeta2_5 = r(nimbeta2_coef_5) var4_5 = r(nimbeta2_var_5) cons4_5 = r(cons4_coef_5) consvar4_5 = r(cons4_var_5) N4_5 = r(N4_5) ///
    nimbeta2_1 = r(nimbeta2_coef_1) var4_1 = r(nimbeta2_var_1) cons4_1 = r(cons4_coef_1) consvar4_1 = r(cons4_var_1) N4_1 = r(N4_1) ///
    ,reps(10) : t2_v3


    ]

    That code breaks by saying


    "
    Parallel Computing with Stata (by GVY)
    Clusters : 8
    pll_id : w8quls7pe1
    Running at : C:\Users\josef\OneDrive - KU Leuven\PhD - Leuven\Banking project\EMPIRICAL\Call Reports Chicago Fed\DepositSensitivity
    Randtype : datetime
    Waiting for the clusters to finish...
    cluster 0003 Exited with error -198- while running the command/dofile (view log)...
    cluster 0005 Exited with error -198- while running the command/dofile (view log)...
    cluster 0006 Exited with error -198- while running the command/dofile (view log)...
    cluster 0007 Exited with error -198- while running the command/dofile (view log)...
    cluster 0008 Exited with error -198- while running the command/dofile (view log)...
    cluster 0001 Exited with error -198- while running the command/dofile (view log)...
    cluster 0002 Exited with error -198- while running the command/dofile (view log)...
    cluster 0004 Exited with error -198- while running the command/dofile (view log)...
    --------------------------------------------------------------------------------
    Enter -parallel printlog #- to checkout logfiles.
    --------------------------------------------------------------------------------
    "


    any ideas?

    Thanks!

  • #2
    Did you click on "view log" and read the actually error message? What it is?
    Does the program run fine on its own? Without using parallel? If so, does it run with the regular simulate command?
    EDIT: note that this is also running an older version of parallel. To update, see: https://github.com/gvegayon/parallel
    Last edited by Felix Bittmann; 11 Apr 2025, 07:06.
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      The code runs for a single run, ie, no parallel. Can't access the logs, the code does not create them

      Thanks!

      Comment


      • #4
        With the current version, the syntax should be:
        Code:
        parallel sim, exp(a=r(returnval)) reps(100) seed(1 2 3 4): t2_v3
        Best wishes

        (Stata 16.1 MP)

        Comment


        • #5
          Hi Felix,

          Thanks for all the help. The thing is now I get this error

          invalid '-'
          stata(): 3598 Stata returned error
          parallel_export_programs(): - function returned error
          parallel_write_do(): - function returned error
          <istmt>: - function returned error


          Any further ideas?

          Thanks!

          Comment

          Working...
          X