Announcement

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

  • Bootstrap in Montecarlo

    I am running some issues on how to run a boostrap in a montecarlo. I need to generate 50 observations of x and y, regress x and y, and bootstrap for the standard error of beta. I need to run this simulation 200 times. I am running into some issues with this code. This is what I've done:




    tempfile maindata2 bootstrap2
    global boots2=50

    clear
    cap prog drop problem1b

    program problem1b, rclass
    drop _all
    set obs 50
    generate x = rnormal()
    generate eps = rnormal() * sqrt(1+exp(x))
    generate y = 2 + 1*x + eps
    save `maindata2'

    forvalues i = 1/$boots2 {
    qui drop _all
    qui use `maindata2'
    bsample /*bootstrap command*/
    reg y x
    regsave
    drop if var=="_cons"
    global betta2=coef
    drop _all
    qui set obs 1
    generate mybeta2 = $betta2
    capture append using `bootstrap2'
    qui save `bootstrap2' , replace
    }

    drop _all
    use `bootstrap2'
    summ mybeta2
    return scalar betaboot = r(mean)
    end

    problem1b

    simulate betaboot = r(betaboot), seed(1001001) reps(200) nodots: problem1b
    summarize betaboot




    I am assuming there is a better way of doing this, or a way that actually works. Any help is deeply appreciated.

    Thank you,

    Miranda

  • #2
    perhaps something like this
    Code:
    program btsreg, eclass
    clear
    set obs 50
    generate x = rnormal()
    generate eps = rnormal() * sqrt(1+exp(x))
    generate y = 2 + 1*x + eps
    bootstrap _b _se:regress y x
    end
    simulate, reps(200):btsreg

    Comment


    • #3
      Thank you so much!!!!
      Does the bootstrap command use 50 observations? Or is it only one?

      Comment


      • #4
        The default option for bootstrap is to use 50 repetitions, but you can request a different number of repetitions:
        Code:
        bootstrap, reps(100):command

        Comment

        Working...
        X