Announcement

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

  • How to graph bootstrap distribution regarding indirect effect estimates and effect ratio?

    To whom that has the expertise on the above questions,

    I used bootstrap methods to test the significance of a hypothesized mediation process with the following commands.

    "capture program drop bootmm

    program bootmm, rclass

    syntax [if] [in]

    sureg (mediator IV controlled_variables i.company i.year) (DV mediator IV controlled_variables i.company i.year) `if' `in'

    return scalar indtotal = [mediator]_b[IV]*[DV]_b[mediator]

    return scalar dir=[DV]_b[IV]

    end

    bootstrap r(indtotal) r(dir), bca reps(5000) nodots: bootmm

    estat boot, percentile bc bca


    Now I need to graph two figures: (1) distribution of values of indirect effect estimates and (2) distribution of values of effect ratio. Attached are examples of these two figures from Shrout and Bolger (2002), corresponding to the following result of bootstrap analysis.
    Refer to: Shrout, P. E., & Bolger, N. (2002). Mediation in experimental and nonexperimental studies: new procedures and recommendations. Psychological Methods, 7(4), 422.
    Click image for larger version

Name:	_20210719205230.png
Views:	1
Size:	177.8 KB
ID:	1619646

    Click image for larger version

Name:	_20210719205257.png
Views:	1
Size:	144.5 KB
ID:	1619647


    Click image for larger version

Name:	_20210719213356.png
Views:	1
Size:	263.3 KB
ID:	1619648

    How to obtain these figures with Stata?

    Thank you!

    Best regards,
    Elaine

  • #2
    Well, you're going to have to rerun what you did, because you did not save the results of the individual bootstrap replications. To do that, you have to specify the -saving()- option in the -bootstrap- prefix, to tell Stata the name of a file in which to save all of those results. Once you do that, it's pretty simple.

    Code:
    bootstrap r(indtotal) r(dir), bca reps(5000) nodots saving(my_results_file, replace): bootmm
    use my_results_file, clear
    histogram indtotal, normal
    gen effect_ratio = indtotal/(indtotal+dir)
    histogram effect_ratio
    The -histogram- command accepts most -graph twoway- options, so you can customize the appearance of those graphs to your preferences.

    I am somewhat surprised you named one of your results indtotal, since what you calculate for it is simply the indirect effect, not the total. I would have just called it ind, or indirect, or somethig like that. The total effect is indirect + direct (or, in your variable names, indtotal + dir). Evidently, Stata doesn't care what you call your variables, and as long as you use them correctly it doesn't matter. But it is usually a good practice to use names that suggest accurately what they represent--it makes it easier for others to understand your code, and also makes it easier for you to see what you did if you have to come back to your code at some point when it is no longer fresh in your memory.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Well, you're going to have to rerun what you did, because you did not save the results of the individual bootstrap replications. To do that, you have to specify the -saving()- option in the -bootstrap- prefix, to tell Stata the name of a file in which to save all of those results. Once you do that, it's pretty simple.

      Code:
      bootstrap r(indtotal) r(dir), bca reps(5000) nodots saving(my_results_file, replace): bootmm
      use my_results_file, clear
      histogram indtotal, normal
      gen effect_ratio = indtotal/(indtotal+dir)
      histogram effect_ratio
      The -histogram- command accepts most -graph twoway- options, so you can customize the appearance of those graphs to your preferences.

      I am somewhat surprised you named one of your results indtotal, since what you calculate for it is simply the indirect effect, not the total. I would have just called it ind, or indirect, or somethig like that. The total effect is indirect + direct (or, in your variable names, indtotal + dir). Evidently, Stata doesn't care what you call your variables, and as long as you use them correctly it doesn't matter. But it is usually a good practice to use names that suggest accurately what they represent--it makes it easier for others to understand your code, and also makes it easier for you to see what you did if you have to come back to your code at some point when it is no longer fresh in your memory.
      Dear Clyde,

      Thank you very much for your great help!

      The problem has been solved with your suggested codes.

      Also thanks a lot for correcting the inappropriate name. I double checked the whole set of codes and made it accurately following your spirit.

      Gratefully,
      Elaine

      Comment

      Working...
      X