Announcement

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

  • Bootstrapping marginal effects using do loop

    Hi Statalist,
    I am using a two-part model to estimate healthcare expenditure for some demographic groups (married unmarried) where I need to bootstrap marginal effects. I have used the following codes (Belotti et al. 2015):
    capture program drop dydx_boot
    program define dydx _boot, eclass
    foreach sex in male female {
    foreach agegroup in age1824 age2544 age4564 age6574 age75over {
    foreach region in neast midw west south {
    di "`region', `sex', `agegroup'"
    svy: twopm totexp married unmarried `controls' if `sex' == 1 & `agegroup' == 1& `region', firstpart(logit) secondpart(glm, family(gamma) link(log))
    margins, dydx(married unmarried) subpop (if `sex' == 1 & `agegroup' == 1 & `region') predict(duan) nose post
    }
    }
    }
    End

    bootstrap _b, seed(1234) reps(100) nodrop: dydx_boot

    While the program codes ran without any errors, the dydx_boot picked the last estimates (female age75over south) only to bootstrap the marginal effects. It did not bootstrap the marginal effects for other estimates. The marginal effects of all estimates were already saved in the memory as executing dydx_boot displayed marginal effects for all estimates. So how can I tell stata to bootstrap marginal effects of all estimates?

    Thanks in advance for your expertise!

    Ramesh Ghimire
    University of Georgia
    Athens, GA 30605


  • #2
    A reference such as

    (Belotti et al. 2015)
    typically points to a detailed bibliography entry that provides some hope of finding the source document. Or a DOI to the publication, or a link to a full-text copy.

    Comment


    • #3
      Belotti et al. 2015. twopm: Two-part models. The Stata Journal, 15(1): 3-20. Available at https://journals.sagepub.com/doi/pdf...867X1501500102

      Comment


      • #4
        From that reference, it appears that the following is the code you adapted to your purposes.
        Code:
        * Marginal effects, averaged over the sample
        capture program drop dydx_boot
        program define dydx_boot, eclass
            twopm exp_tot c.age i.female, firstpart(logit) secondpart(regress, log)
            margins, dydx(*) predict(duan) nose post
        end
        Now, the way bootstrap works, and the way it is used in this code, is that the program bootstrapped (dydx_boot) provides the results of a single run of the model being bootstrapped, and the results returned by the program are the input to the bootstrap estimation. You are, apparently, trying to build 40 separate bootstrapped models, fitting each combination of sex, agegroup, and region separately.

        The looping done within your dydx_boot must in fact be done outside dydx_boot.

        However I am not an expert in two part modeling, and have concerns about the structure your two part model, so I cannot carry on further with a recommendation for how to accomplish this.


        Comment

        Working...
        X