Announcement

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

  • Command not found error of self design bootstrap

    Here is a snippet of my code, and the environment is Stata 16SE. I receive the error message as follows:
    Code:
    capture program drop myboot
    program define myboot, rclass
        args i
        preserve
        bsample
        gen new7`i'id=id
        xtset new7`i'id qdate
        xtreg F`i'.y $bplinshock $bplinxlist, fe robust
        scalar bylinh`i'=\_b[$bplinshock]
        gen new8`i'id=id
        xtset new8`i'id qdate
        xtreg F`i'.g $bplinshock $bplinxlist, fe robust
        scalar bglinh`i' = \_b[$bplinshock]
        scalar sumliny = bylinh`i' + sumliny
        scalar sumling = bglinh`i' + sumling
        return scalar multlinh`i'=sumliny/sumling
        restore
    end
    
    forvalues i = 1/20 {
    
    clear all
    set obs 100
      
    simulate multlinh`i'=r(multlinh`i'), reps(100): myboot `i'
    sum
    bstat, stat(multlinh`i'\_obs) n(100)
    estat bootstrap, all
      }
    Code:
      
     myboot command not found r(111);

  • #2
    Maybe change
    Code:
    clear all
    to
    Code:
    drop _all
    I can't actually follow your code, but it looks as if even that change won't make it work.

    I guess that this thread is a continuation of the one over in the Mata subforum? When you get your next error message, you can add to this thread rather than starting a third.

    Comment


    • #3
      I also do not see what this program is supposed to do, but the particular error message is certainly caused by -clear all- as Joseph suggested. -clear all- among dropping many other things, drops also all defined programs. So by the time the program is called, it is not in the memory anymore.

      Code:
      help clear

      Comment


      • #4
        Really appreciate your help! Thank you so much~

        Comment


        • #5
          Hi! I am bothering you again. Very much thanks for the help. I modified my code following the recommended instructions. The main idea of the program is to carry out two xtreg regressions and derives the _b1[] and _b2[] in order to simulate the _b1[]/_b2[]. Unfortunately, I still receive the error message as follows:
          Code:
          save SmallOpenEconomy1.dta,replace
            
          capture program drop myboot
          program define myboot, rclass
              args i
              preserve
              use SmallOpenEconomy1.dta, clear
              gen new7`i'id=id
              gen new8`i'id=id
              bsample, cluster(id) idcluster(new7`i'id)
              xtset, clear
              xtset new7`i'id qdate
              xtreg F`i'.y $bplinshock $bplinxlist, fe robust
              scalar bylinh`i'= _b[$bplinshock]
              bsample, cluster(id) idcluster(new8`i'id)
              xtset, clear
              xtset new8`i'id qdate
              xtreg F`i'.g $bplinshock $bplinxlist, fe robust
              scalar bglinh`i' =  _b[$bplinshock]
              replace sumliny = bylinh`i' + sumliny
              replace sumling = bglinh`i' + sumling
              return scalar multlinh`i'=sumliny/sumling
              restore
          end
          
          forvalues i = 1/20 {
          
          drop _all
          set obs 100
            
          simulate multlinh`i'=r(multlinh`i'), reps(100): myboot `i'
          sum
          bstat, stat(multlinh`i') n(100)
          estat bootstrap, all
            }
          Code:
          repeated time values within panel
          an error occurred when simulate executed myboot

          Comment


          • #6
            Originally posted by Ning Wei View Post
            The main idea of the program is to carry out two xtreg regressions and derives the _b1[] and _b2[] in order to simulate the _b1[]/_b2[].
            If that's what your objective is, then your code seems at least to me to go off the rails. (I'm still not sure what it is you're trying to accomplish.)

            Regardless, from the looks of it, your current error is coming from your xtset command, because you're drawing a random sample with replacement just beforehand.

            Comment


            • #7
              The problem might be coming from this
              Code:
              gen new7`i'id=id
              bsample, cluster(id) idcluster(new7`i'id)
              I do not know what this does.

              I think the way how you are supposed to use this construct is, you have a variable id which identifies the cluster, idnew does not exist in your data, then you write

              Code:
              bsample, cluster(id) idcluster(idnew)
              I tried and I see that if you already have in your data idnew, like you do, bsample does not generate an error. But whether this does what you think is a different story.

              My guess is that the when a cluster gets resampled more than once, the way how you do it does not result in a unique idnew, and hence the repeated values in your bootstrap samples.

              Comment


              • #8
                Thank you so much!!!!!!! (*^▽^*)After the modification, I finally generate a satisfying output.
                Code:
                save SmallOpenEconomy1.dta,replace
                  
                capture program drop myboot
                program define myboot, rclass
                    args i
                    preserve
                    use SmallOpenEconomy1.dta, clear
                    bsample, cluster(id) idcluster(idnew)
                    xtset, clear
                    xtset idnew qdate
                    xtreg F`i'.y $bplinshock $bplinxlist, fe robust
                    scalar bylinh`i'= _b[$bplinshock]
                    xtreg F`i'.g $bplinshock $bplinxlist, fe robust
                    scalar bglinh`i' =  _b[$bplinshock]
                    replace sumliny = bylinh`i' + sumliny
                    replace sumling = bglinh`i' + sumling
                    return scalar multlinh`i'=sumliny/sumling
                    restore
                end
                
                forvalues i = 1/20 {
                
                drop _all
                set obs 100
                  
                simulate multlinh`i'=r(multlinh`i'), reps(100): myboot `i'
                sum
                  }
                This can perfectly work out the problem.
                Code:
                Simulations (100)
                ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
                ..................................................    50
                ..................................................   100
                
                    Variable |        Obs        Mean    Std. Dev.       Min        Max
                -------------+---------------------------------------------------------
                   multlinh8 |        100    .5106296    .0709337   .3720216   .7186825
                number of observations (_N) was 0, now 100

                Comment

                Working...
                X