Announcement

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

  • Program + Foreach

    Hi there,

    I am a new user here in this forum, so this is my first thread. My question:

    I am trying to run the following code combining in some sense both the foreach and program commands. However, for some reason I am not able to execute it properly. If someone can see the mistake, please let know how to solve it. Thank you in advance for you time.

    program define myboot, rclass
    args x
    reg `x' elig esse elig_esse [aw=k_`x'] if select1==1 & esse!=0, robust
    local a = _b[elig]
    reg qu_m1 elig esse elig_esse [aw=k_`x'] if select1==1 & esse!=0, robust
    local b = _b[elig]
    return scalar ratio = a/b
    end

    foreach var of varlist lncn lnwr lnfoodh lnfoodout lnleisure lnotro lngasto {

    bootstrap ratio_`var'=r(ratio), reps(50): myboot `var'

    }
    capture program drop myboot
    Last edited by Sebastian Faundez; 07 Aug 2019, 11:07.

  • #2
    Hi Sebastian
    One tip for future troubleshooting Bootstrap bugs. Run the command on its own, without bootstrap, twice, to see if that reports any problem
    If you do that, you will see it says. "a not found"

    where "a" is your local.
    substitute
    return scalar ratio = a/b
    with
    return scalar ratio = `a'/`b'
    HTH
    Fernando

    Comment


    • #3
      Thank you Fernando! now it worked perfectly.



      Comment

      Working...
      X