Announcement

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

  • Bootstrapping interaction variables

    I have run a two stage spline model. Where the first stage controls for endogeinity in the number of antenatal care visits a pregnant woman makes. In my previous analysis I did find that antenatal care is only effective up to 4 visits in reducing low birth weight. So in the second stage I went to generate an spline at 4 visits of which I tried to interact with one of the antenatal care services; if a woman was given Malaria prophylaxis during the antenatal care visit as follows;

    reg LBW c.prophylaxis##c.ANC4 c.prophylaxis##c.ANC1 uhat SS1 `varlist' . That's the second stage. I wanted to bootstrap the Wald test results from the interaction variable. But I keep getting an error.

    The full code is as follows;

    set more off
    set seed 12345
    cap program drop iv_wald
    program define iv_wald, rclass
    args varlist
    reg ANC rain ib0.educ married miscarriage caesar ib1.SES age age2 ib1.birthorder wanted permission ib1.religion urban ib1.ethnic
    cap drop uhat
    predict uhat, res
    return scalar b_iv = _b[rain]
    reg LBW c.prophylaxis##c.ANC4 c.prophylaxis##c.ANC1 `varlist' uhat SS1
    return scalar b1 = _b[c.prophylaxis##c.ANC4]
    return scalar b2 = _b[c.prophylaxis##c.ANC1]
    return scalar b_uhat = _b[uhat]
    return scalar b_SS1=_b[SS1]
    end
    local controls = "gestation NDVI sex ib0.educ married twin miscarriage caesar ib1.SES age age2 ib1.birthorder wanted permission ib1.religion urban ib1.ethnic smoking"

    bootstrap b_iv=r(b_iv) b1=r(b1) b2=r(b2) b_uhat = r(b_uhat) b_SS1=r(b_SS1), reps(1000): iv_wald `controls'



    The error that I got is as follows;

    invalid matrix stripe;
    c.prophylaxis##c.ANC4
    an error occurred when bootstrap executed iv_wald
    r(198);


    If anyone knows the reason why, please help.

    Thanks


  • #2
    If you want to store the coefficient of the interaction term than that is c.prophylaxis#c.ANC4 instead of c.prophylaxis##c.ANC4. the ## says add the main effects and the interaction terms to the model the interaction term themselves are named with just one #.

    When doing something like that I always first run the program iv_wald as is, without bootstrap in front of it. This just runs the program on the current dataset. This should work without an error message. If there is an error message, it is easier to find what the problem is. In your case it would return an error message. Than I would type

    Code:
    set traced  1
    set trace on
    iv_wald
    This would show the commands executed by iv_wald and show where in the iv_wald command the error occurred. In your case that would probably be the line

    Code:
    return scalar b1 = _b[c.prophylaxis##c.ANC4]
    Ok, the name of that parameter is complex, so typos can quickly happen. So that would be my first thing to check. You can add the coeflegend option to reg to see how the coefficients are called. so you can type something like

    Code:
    reg LBW c.prophylaxis##c.ANC4 c.prophylaxis##c.ANC1 `varlist' uhat SS1, coeflegend
    And look at the name for the interaction term, which will probably be _b[c.prophylaxis#c.ANC4]
    Last edited by Maarten Buis; 17 Jan 2018, 05:02.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you Maarten. It worked, I removed one hashtag from the interaction

      Comment

      Working...
      X