Announcement

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

  • Saving margins estimates with bootstrap se after Two Part models

    Hi all,
    I am estimating a two-part model (twopm) and want to store the margins estimates with the correct bootstrap standard errors - to later plot several models combined in a combomarginsplot.
    Here is an example of what I am trying to do, what should I change in my code so it will store it correctly?:


    Code:
    program define dydx_boot, eclass
    qui twopm y i.age if female==0, firstpart(logit) second part(regress, log) vce(cluster id)
    qui margins, at(age=(21(1)42)) predict(duan) post nose
    end
    
    bootstrap _b, saving(male, replace) seed(14) reps(1000):dydx_boot
    
    
    capture program drop dydx_boot
    
    program define dydx_boot, eclass
    qui twopm y i.age if female==1, firstpart(logic) second part(regress, log) vce(cluster id)
    qui margins, at(age=(21(1)42)) predict(duan) post nose
    end
    
    bootstrap _b, saving(female, replace) seed(14) reps(1000):dydx_boot
    
    
    combomarginsplot male female

    Much appreciated,
    Alon

  • #2
    Once the bootstrap command has executed, the estimates should be available in memory. So just store them.

    Code:
    bootstrap _b, saving(male, replace) seed(14) reps(1000):dydx_boot
    estimates store male
    and

    Code:
    bootstrap _b, saving(female, replace) seed(14) reps(1000):dydx_boot
    estimates store female

    Comment


    • #3
      Thank you Andrew,

      Maybe my usage of the word "store" in the question was misleading.
      I want to save the margins results after bootstrap as a .dta
      The code I posted, saves the 1000 bootstrap replications.




      Comment


      • #4
        The estimates are from the bootstrap command, so there is no option to do what margins does. You can use marginsplot following bootstrap (or using the stored estimates) or construct the dataset with these estimates.

        Comment

        Working...
        X