Announcement

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

  • Bootstrapping the product of coefficients from separate estimations

    Hi all,

    I am trying to estimate standard error for the product of coefficients using a program below (labelled in code below as: indirect)
    I can bootstrap all the estimates separately however when I try to estimate the standard error for the product of coefficients from two separate regressions it won't work. Although the boot strap program will return an estimate without any errors, it won't return a standard error.

    I have also tried:
    - nlcom
    - generating temp var instead of scalars and then using this to calculate the indirect effect (returns an error when I bootstrap)
    - the 'ml_mediation' program which details bootstrapping which I followed does not seem to be available anymore therefore I wrote the below program instead

    Code:
    Code:
    program boot1, rclass
    syntax [if] [in]
     
    xtmixed y z x c || newid:, reml // estimates mediator and treatment effects on Y
    return scalar direct = _b[x] //scalar for direct effect
    return scalar mediation_2 = _b[z] //scalar for indirect pathway 2
    
    xtmixed z x c || newid:, reml // estimated indirect effect on mediator 
    return scalar mediation_1 = _b[x] //scalar for indirect pathway 1
    
    return scalar indirect = mediation_2 * mediation_1 // product of coefficients calculating the indirect pathway
    
    return list
    
    end
    
    set seed 1
    bootstrap r(direct) r(mediation_2) r(mediation_1) r(indirect), cluster(id) idcluster(newid) rep(10): boot1

    Thank you in advance.

  • #2
    Could just compute it from the bootstrapped means and SEs?
    HTML Code:
    https://stats.stackexchange.com/questions/498224/standard-error-of-estimated-sum-or-product-mean

    Comment


    • #3
      Hi Yumi Nito

      Did you find a solution in the end? I am facing the same issue.

      Thank you in advance

      Kind regards
      Eva

      Comment


      • #4
        The code shown in #1 fails because it has been bitten by a common misunderstanding of how the -return scalar- command works. In particular, -return scalar whatever = some expression- does not create a scalar named whatever. All that the mention of the word "scalar" in that command does is inform Stata that what is about to be returned in -r()- is the value of an expression, not a matrix or a macro. But it does not create a scalar. Consequently, when the command -return scalar indirect = mediation_2 * mediation_1- is reached, mediation_2 and mediation_1 are both undefined and the program breaks there.

        I believe the following would work, although I have not tested it:
        Code:
        program boot1, rclass
        syntax [if] [in]
         
        xtmixed y z x c || newid:, reml // estimates mediator and treatment effects on Y
        return scalar direct = _b[x] //scalar for direct effect
        scalar mediation_2 = _b[z] // DEFINE A SCALAR FOR LATER USE
        return scalar mediation_2 = mediation_2 //scalar for indirect pathway 2
        
        xtmixed z x c || newid:, reml // estimated indirect effect on mediator
        scalar mediation_1 = _b[x] // DEFINE A SCALAR FOR LATER USE
        return scalar mediation_1 = mediation_1 //scalar for indirect pathway 1
        
        return scalar indirect = mediation_2 * mediation_1 // product of coefficients calculating the indirect pathway
        
        return list // THIS COMMAND DOES NOT LIST THE RETURN VALUES OF PROGRAM boot1!
        // IT LISTS THE RETURN VALUES OF THE IMMEDIATELY PRECEDING COMMAND, WHICH, I THINK,
        // DO NOT EXIST
        
        end
        
        set seed 1
        bootstrap r(direct) r(mediation_2) r(mediation_1) r(indirect), cluster(id) idcluster(newid) rep(10): boot1

        Comment

        Working...
        X