Announcement

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

  • Syntax error when boostrapping

    Hi everyone,

    I've been attempting to run a two-step bootstrap (for background see http://www.statalist.org/forums/foru...age-estimation) but keep encountering an invalid syntax (r(198)) error in the simulate stage. Have tried numerous ways to resolve the issue but to no avail, and was wondering if anyone could point me in the right direction.

    This is the code I'm running:

    Code:
    cd "(my file location)"
    
    set trace on
    set traced 1
    
    ma drop _all
    scalar drop _all
    
    * write program
    capture program drop prog_boot
    program prog_boot, eclass
        syntax varlist [if]
            use file1, clear
            preserve
            foreach m in 0 1 {
                foreach p in 1101 1401 1402 1404 1414 1423 2101 2102 2107 2112 2114 3201 3202 3203 ///
                        3204 3206 3209 3213 3233 3401 3402 3403 3404 3416 3432 4101 4102 4104 4105 4107 ///
                        4201 4206 4210 4222 4231 4232 4401 4406 4408 4412 4413 4415 4433 4452 5001 5101 ///
                        5105 5108 5113 5114 5301 5303 5305 5325 5327 5329 5332 6201 6223 6227 {
                            bsample if male==`m' & wave==`1995' & county==`p' & inreg==1 //get bootstrap sample
                            reg var1 var2 var3 var4 var5 var6 ///
                                if male==`m' & wave==`1995' & county==`p' //perform regression
                            scalar var1995`p'`m'=_b[var2]
                            scalar int1995`p'`m'=_b[_cons]
                            }
                }
            restore
            
            use file1, clear
            marksample touse // mark relevant sample
            preserve
                    bsample 100 if `touse' //generate bootstrap sample for second stage
                        foreach p in 1101 1401 1402 1404 1414 1423 2101 2102 2107 2112 2114 3201 3202 3203 ///
                            3204 3206 3209 3213 3233 3401 3402 3403 3404 3416 3432 4101 4102 4104 4105 4107 ///
                            4201 4206 4210 4222 4231 4232 4401 4406 4408 4412 4413 4415 4433 4452 5001 5101 ///
                            5105 5108 5113 5114 5301 5303 5305 5325 5327 5329 5332 6201 6223 6227 {
                                foreach m in 0 1 {
                                    replace var=var1995`p'`m' if county==`p' & male==`m' & wave==1995
                                    replace int=int1995`p'`m' if county==`p' & male==`m' & wave==1995
                                    }
                            }
                    
                    regress `varlist' i.yob //do second stage regression
            restore
        
    end
    
    * run regression
    use file2, clear
    qui reg var2 var int var7 var8 var9 var10 var11 i.yob if wave==1995 & edreg==1 //run actual regression
    scalar nobs = e(N) //save no. of observations
    scalar rsqd = e(r2) //save R^2
    matrix coef = e(b) //save coeff matrix
    
    * bootstrap
    simulate _b, reps(50): prog_boot var2 var int var7 var8 var9 var10 var11 if edreg==1 & wave==1995
    bstat, stat(coef)
    Would be very grateful for any help!

  • #2
    Have you set the tracedepth deeper until you see just what line is giving rise to the error?

    Just scanning your code, I always thought that int is reserved and cannot be used as a variable name, but that would call up a different error code, I believe.

    Comment


    • #3
      Hi Joseph,

      Thanks for your reply! The error occurred in the simulate command line, specifically:

      Code:
          - local seed `c(seed)'
          = local seed Xd63d4dc12afac720bfceef7a838d1c4700024819
          - `noi' di as inp `". `command'"'
          = * di as inp `". prog_boot var2 var int1 var7 var8 var9 var10 var11 if edreg==1 & wave==1995"'
          - _prefix_clear, e r
          - `traceon'
          =
          - capture noisily quietly `noisily' `version' `command'
          = capture noisily quietly  version 12: prog_boot var2 var int1 var7 var8 var9 var10 var11 if edreg==1 & wave==1995
      invalid syntax
          - `traceoff'
          =
          - local rc = c(rc)
          - if `rc' {
          = if 198 {
          - _prefix_run_error `rc' simulate `cmdname'
          = _prefix_run_error 198 simulate prog_boot
      an error occurred when simulate executed prog_boot
            }
          ----------------------------------------------------------------------------------------- end simulate.Simulate ---

      Comment


      • #4
        Is this correct?
        Code:
        if male==`m' & wave==`1995' & county==`p' //perform regression
        Is 1995 supposed to be a macro?
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #5
          That is indeed the problem, thank you so much for spotting it. Saved me a great deal of head-scratching.
          Last edited by James Henning; 17 Apr 2016, 20:14.

          Comment


          • #6

            If I could go back to a question from my first thread (http://www.statalist.org/forums/foru...age-estimation), is it possible to adjust standard errors for clustering when bootstrapping using the -simulate- command?

            Comment

            Working...
            X