Announcement

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

  • Help with boostrap code for indirect effects using gsem

    Hello,
    I am trying to obtain coefficients, bootstrap standard errors and percentile CI for an indirect effect using gsem. I saw this code online


    Code:
     
     capture program drop boot1  
     program boot1, rclass  
     gsem (Y<- X1 i.X2 X3 Z P[province] C[province>district_no]) ///  
     (Z<-X1 i.X2 X3 P[province] C[province>district_no]), nocapslatent latent (P C)  
     return scalar X1_indirect=(_b[Z:X1]*_b[Y:Z])  
     return scalar X21_indirect=(_b[Z:1.X2]*_b[Y:Z])  
     return scalar X22_indirect=(_b[Z:2.X2]*_b[Y:Z])  
     return scalar X3_indirect=(_b[Z:X3]*_b[Y:Z])  
     end  
     bootstrap r(X1_indirect) r(X21_indirect) r(X22_indirect) r(X3_indirect), seed(12345) reps(200): boot1 estat boot, bc percentile
    This works but it instead of just showing the outputs for X1_indirect, X21_indirect, and X3_indirect which it does now, I also want to see the output for these portions of the code

    Code:
     
     gsem (Y<- X1 i.X2 X3 Z P[province] C[province>district_no]) ///  
     (Z<-X1 i.X2 X3 P[province] C[province>district_no]), nocapslatent latent (P C)
    Could someone help me with how to edit the code in a way that it would show me the outputs for these section too?

    Thanks in advance!

  • #2
    -bootstrap- has a -noisily- option that will show you all the output from each rep.

    But what are you going to do with the output from 200 replications of -gsem-? It will be voluminous, and I don't see how you will be able to read and understand it or do anything useful with it.

    Comment


    • #3
      Thanks Clyde Schechter but I dont really want to see the output for the 200 replications needed to generate the indirect effects.

      I just wanted to see what the outputs for this section is (in addition to the bootstrapped indirect effects)

      Code:
        gsem (Y<- X1 i.X2 X3 Z P[province] C[province>district_no]) ///    (Z<-X1 i.X2 X3 P[province] C[province>district_no]), nocapslatent latent (P C)
      Would that be possible?

      I know how to do it without bootstrapping but Im required to use bootstrapping for my dataset so Im having a hard time figuring out the code.
      Without bootstrapping, my codes will simply be

      Code:
      gsem (Y<-X1 M controls)(M<X1 controls)
      *to get the indirect effect, I will do
      nlcom _b[Y:M]*_b[M:X1]
      *the code is not directly the same as above but the logic remains

      Comment


      • #4
        Just run that code separately, before or after the bootstrap. I don't think there is any way to get -bootstrap- to show the output of the underlying analysis on the original sample.

        If you didn't have random effects in the model, you could switch from -gsem- to -sem-. Then -sem- allows you to specify -vce(bootstrap)- instead of directly using the -bootstrap- command. The output for that would show you the coefficients from the underlying analysis, but the standard errors and its sequel statistics would be calculated by bootstrapping. Unfortunately, -gsem- does not support -vce(bootstrap)-, and -sem- doesn't support group level latent variables.

        Comment


        • #5
          Thank you Clyde Schechter . That's my initial thought as well..

          Comment

          Working...
          X