Announcement

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

  • Bootstrap estimation

    I need to compute standard errors for estimated coefficients of a regression model however, I'm encountering some issues in implementing this in Stata. I want to use a two-stage non-parametric bootstrap procedure with two-way clustering at the country and year level in order to compute the standard errors for the estimated coefficients.

    The format of my data before reshaping is such that I have columns for the variables of the regression (for example d_spread_africa and ldspread_africa)
    So my regression (without bootstrap) would look like this.
    Code:
    foreach country in africa middleeast {
        xtreg dspread_`country' ldspread_`country' L(1/12).unct_`country', fe robust
        eststo xreg_`country'
        esttab xreg_`country' using xreg_`country'.tex, title("Benchmark Regression fe") replace
    }
    I thought it would be easier to use bootstraping if I reshape the data to have a country and year variable.
    Here’s how I reshaped the data:
    Code:
    reshape long spread_ wui_ dspread_ ldspread_ dwui_ unct_, i(ward_num monthlyvar) j(country) string
    gen yearvar = year(dofm(monthlyvar))
    sort ward_num monthlyvar country
    And I am trying to use the following bootstrap command:
    Code:
    bootstrap, reps(100) cluster(country yearvar): xtreg dspread_* ldspread_* L(1/12).unct_*, fe vce(robust)
    However I get this error:
    . bootstrap, reps(100) cluster(country yearvar): xtreg dspread_ ldspread_ L(1/12).unct_, fe vce(robust)
    (running xtreg on estimation sample)
    not sorted
    an error occurred when bootstrap executed xtreg
    r(5);
    The data looks like this
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long ward_num float(monthlyvar yearvar) str14 country float(dspread_ ldspread_ unct_)
    1 660 2015 "africa"       -.01273128   .014274824 0
    1 660 2015 "middleeast"  -.017508611   .019569613 0
    1 661 2015 "africa"      -.015691198   -.01273128 0
    1 661 2015 "middleeast"    .03139296  -.017508611 0
    1 662 2015 "africa"        .08255005  -.015691198 0
    1 662 2015 "middleeast"  -.034069523    .03139296 0
    1 663 2015 "africa"       -.05759017    .08255005 0
    1 663 2015 "middleeast"   .016335353  -.034069523 0
    1 664 2015 "africa"       .035960466   -.05759017 0
    1 664 2015 "middleeast"  -.008077189   .016335353 0
    1 665 2015 "africa"       .016428001   .035960466 0
    1 665 2015 "middleeast"  -.031927027  -.008077189 0
    1 666 2015 "africa"     -.0044620577   .016428001 0
    1 666 2015 "middleeast"  -.008583674  -.031927027 0
    1 667 2015 "africa"     -.0003889892 -.0044620577 0
    1 667 2015 "middleeast"   -.02492235  -.008583674 0
    1 668 2015 "africa"      -.024398034 -.0003889892 0
    1 668 2015 "middleeast"    .05400065   -.02492235 0
    1 669 2015 "africa"        .02820484  -.024398034 1
    1 669 2015 "middleeast"  -.001000002    .05400065 0
    1 670 2015 "africa"       -.01822365    .02820484 0
    1 670 2015 "middleeast"  -.008926474  -.001000002 0
    1 671 2015 "africa"      .0039288327   -.01822365 0
    1 671 2015 "middleeast"    .01623942  -.008926474 0
    1 672 2016 "africa"      -.002127517  .0039288327 0
    1 672 2016 "middleeast"   -.01431036    .01623942 0
    1 673 2016 "africa"        .04208383  -.002127517 0
    1 673 2016 "middleeast"  .0015582517   -.01431036 0
    1 674 2016 "africa"       -.01246523    .04208383 0
    1 674 2016 "middleeast"   -.04449745  .0015582517 0
    1 675 2016 "africa"        .05236107   -.01246523 0
    1 675 2016 "middleeast"    .01941245   -.04449745 0
    1 676 2016 "africa"      -.026499826    .05236107 0
    1 676 2016 "middleeast"   -.01979743    .01941245 0
    1 677 2016 "africa"       -.02334593  -.026499826 0
    1 677 2016 "middleeast"   -.02490872   -.01979743 0
    1 678 2016 "africa"       .015093558   -.02334593 1
    1 678 2016 "middleeast"   -.03613212   -.02490872 1
    1 679 2016 "africa"      -.011342783   .015093558 0
    1 679 2016 "middleeast"   .025140826   -.03613212 0
    1 680 2016 "africa"        .04714107  -.011342783 0
    1 680 2016 "middleeast"   .033584423   .025140826 0
    1 681 2016 "africa"       -.07134539    .04714107 0
    1 681 2016 "middleeast"  -.011004753   .033584423 0
    1 682 2016 "africa"        .05198849   -.07134539 0
    1 682 2016 "middleeast"   .005849187  -.011004753 0
    1 683 2016 "africa"       -.02892708    .05198849 1
    1 683 2016 "middleeast"   .013701008   .005849187 0
    2 660 2015 "africa"       -.01273128   .014274824 0
    2 660 2015 "middleeast"  -.017508611   .019569613 0
    2 661 2015 "africa"      -.015691198   -.01273128 0
    2 661 2015 "middleeast"    .03139296  -.017508611 0
    2 662 2015 "africa"        .08255005  -.015691198 0
    2 662 2015 "middleeast"  -.034069523    .03139296 0
    2 663 2015 "africa"       -.05759017    .08255005 0
    2 663 2015 "middleeast"   .016335353  -.034069523 0
    2 664 2015 "africa"       .035960466   -.05759017 0
    2 664 2015 "middleeast"  -.008077189   .016335353 0
    2 665 2015 "africa"       .016428001   .035960466 0
    2 665 2015 "middleeast"  -.031927027  -.008077189 0
    2 666 2015 "africa"     -.0044620577   .016428001 0
    2 666 2015 "middleeast"  -.008583674  -.031927027 0
    2 667 2015 "africa"     -.0003889892 -.0044620577 0
    2 667 2015 "middleeast"   -.02492235  -.008583674 0
    2 668 2015 "africa"      -.024398034 -.0003889892 0
    2 668 2015 "middleeast"    .05400065   -.02492235 0
    2 669 2015 "africa"        .02820484  -.024398034 1
    2 669 2015 "middleeast"  -.001000002    .05400065 0
    2 670 2015 "africa"       -.01822365    .02820484 0
    2 670 2015 "middleeast"  -.008926474  -.001000002 0
    2 671 2015 "africa"      .0039288327   -.01822365 0
    2 671 2015 "middleeast"    .01623942  -.008926474 0
    2 672 2016 "africa"      -.002127517  .0039288327 0
    2 672 2016 "middleeast"   -.01431036    .01623942 0
    2 673 2016 "africa"        .04208383  -.002127517 0
    2 673 2016 "middleeast"  .0015582517   -.01431036 0
    2 674 2016 "africa"       -.01246523    .04208383 0
    2 674 2016 "middleeast"   -.04449745  .0015582517 0
    2 675 2016 "africa"        .05236107   -.01246523 0
    2 675 2016 "middleeast"    .01941245   -.04449745 0
    2 676 2016 "africa"      -.026499826    .05236107 0
    2 676 2016 "middleeast"   -.01979743    .01941245 0
    2 677 2016 "africa"       -.02334593  -.026499826 0
    2 677 2016 "middleeast"   -.02490872   -.01979743 0
    2 678 2016 "africa"       .015093558   -.02334593 1
    2 678 2016 "middleeast"   -.03613212   -.02490872 1
    2 679 2016 "africa"      -.011342783   .015093558 0
    2 679 2016 "middleeast"   .025140826   -.03613212 0
    2 680 2016 "africa"        .04714107  -.011342783 0
    2 680 2016 "middleeast"   .033584423   .025140826 0
    2 681 2016 "africa"       -.07134539    .04714107 0
    2 681 2016 "middleeast"  -.011004753   .033584423 0
    2 682 2016 "africa"        .05198849   -.07134539 0
    2 682 2016 "middleeast"   .005849187  -.011004753 0
    2 683 2016 "africa"       -.02892708    .05198849 1
    2 683 2016 "middleeast"   .013701008   .005849187 0
    3 660 2015 "africa"       -.01273128   .014274824 0
    3 660 2015 "middleeast"  -.017508611   .019569613 0
    3 661 2015 "africa"      -.015691198   -.01273128 0
    3 661 2015 "middleeast"    .03139296  -.017508611 0
    end
    format %tm monthlyvar
    label values ward_num ward_num
    label def ward_num 1 "E05009317", modify
    label def ward_num 2 "E05009318", modify
    label def ward_num 3 "E05009319", modify
    Could anyone provide guidance on how to correctly implement this bootstrap procedure in Stata?

    Much appreciated

  • #2
    Dear Andrew Clarke,

    I am afraid I do not have the answer to your question, but I can add to your list of problems. As far as I understand, the bootstrap command does not do two-way clustering: it does one-way clustering based on a variable defined by the pairs of the variables listed in the cluster option. Additionally, you would need to use the idcluster option and use that to define the fixed effects in xtreg. However, I feel the first issue is a show stopper. It is probably better to use analytical two-way clustered standard errors (e.g., as provided by reghdfe).

    Best wishes,

    Joao

    Comment

    Working...
    X