Announcement

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

  • Bootstrapping after gsem

    Hello

    I am trying to test for a mediation effect using the gsem and boostrapping.
    I am consistently running into a problem where the bootstrapping returns a series of 'x's with the message:
    insufficient observations to compute bootstrap standard errors
    no results will be saved

    Looking at related posts, I think there must be something with my code, but I cannot figure out what the problem is.
    Below are my codes.

    If anyone can provide wisdom on this matter, it would be greatly appreciated.
    Many thanks in advance.


    Code:
    global key_control2 "L2.ln_at L2.ln_firmage L2.tobinq L2.sgrowth L2.unabsorbedslack L2.exploratoryratio L2.comp2_w L2.ln_total_env_viol_amount L2.toxic"
    
    capture program drop boot1
    program boot1, rclass
    gsem (L1.ln_invest2 <- L2.tran_risk_pro_w_std $key_control2 i.gvkey i.year)(tobinq <- L1.ln_invest2 L2.tran_risk_pro_w_std $key_control2 i.gvkey i.year) if sample==1
    return scalar IV_indirect = (_b[tobinq:L1.ln_invest2]*_b[L1.ln_invest2:L2.tran_risk_pro_w_std])
    return scalar IV_direct = (_b[tobinq:L2.tran_risk_pro_w_std])
    return scalar IV_total = (_b[tobinq:L2.tran_risk_pro_w_std]+_b[tobinq:L1.ln_invest2]*_b[L1.ln_invest2:L2.tran_risk_pro_w_std])
    return scalar Mediator_direct = (_b[tobinq:L1.ln_invest2])
    end
    bootstrap r(IV_indirect) r(IV_direct) r(IV_total) r(Mediator_direct), seed(12345) reps(500) nodrop: boot1 estat boot, bc percentile

  • #2
    I think the problem is the if-condition in your sem command. I suggest you first create a dataset that only contains the relevant sample and then use this sample for bootstrapping. And make sure that your program runs fine before using it in combination with bootstrapping.
    Best wishes

    (Stata 18.0 MP)

    Comment


    • #3
      Thank you for your suggestion Felix.
      I've tried following your direction, but the problem still persists, unfortunately.

      Comment


      • #4
        And then program runs fine and reports all return values as intended when you run it on the actual data before the bootstrap?
        Best wishes

        (Stata 18.0 MP)

        Comment


        • #5
          I apologize for the late response.
          Yes, the program runs fine before the bootstrap. The problem arises with the bootstrap command. Still trying to figure it out.

          Comment


          • #6
            Without the data I can only guess. Maybe it has to do with missing values or something or your sample selection, as stated above. I suggest the following. Take a bootstrap resample manually and then run the program again. By doing so it might be easier to spot the problem.

            Like:

            Code:
            (Define program)
            boot1  // Test run
            bsample  // Take bootstrap sample from your dataset
            boot1
            Best wishes

            (Stata 18.0 MP)

            Comment

            Working...
            X