Announcement

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

  • Using "outreg2" after bootstrap program

    Statalisters,

    I am attempting to use "outreg2" after running a pre-defined bootstrap program, but cannot seem to use the command to tabulate only a subset of the estimates.

    The code below is a much simpler version of the code i am using but its purpose is the same - it attempts to run a bootstrap estimation program on three (but possibly more) independent variables then merge a subset of the results from each estimation in to one LaTeX table. A problem seems to arise, however, when using the "outreg2" command in that i only ever get tables including all results as opposed to the subset asked for. No errors are returned, Stata simply seems to be running over the "outreg2" command ignoring the request for specific variables. If i explicitly use a varlist as opposed to a local macro, the same thing happens.

    I was wondering if anyone had an idea what i am doing wrong? I suspect it is something quite small i am overlooking, but would appreciate greatly any advice.

    As a side note, the code that merges these tables together (from the line "tempvar j" onwards) seems incorrect to me. I am trying to change the command used to export tables for each element of the local macro "outputs", but am unsure how to do this correctly so the code can be used for a larger set of independent variables. Any advice on this would also be extremely helpful.

    Thanks in advance for any help/time.

    Mark


    Code:
    local outputs "VAR1 VAR2 VAR3"
    local dirstub "FILEPATH"
            
    foreach x of local outputs{
    
        bootstrap est1 = r(fl`x') ets2 = r(`x'var1) est3 = r(`x'var2) est4 = r(`x'var3),  reps(100) seed(123): strucboot `x'
        
        local tabopts "bdec(3) stats(coef, se, ci,) bracket(ci) paren(se) alpha (0.01, 0.05, 0.10) symbol(***,**,*)  nonotes "    
        local strucparms "est1 est2"
        tempvar j
        gen `j' = length("`outputs'")
        gettoken first rest: outputs
        tempvar k
        gen `k' = length("`first'")
        tempvar i
        gen `i' = `j'-`k'
    
        if strpos("`outputs'","`x'") == 1{
    
            outreg2 using "`dirstub'\\stataoutput\tab1", replace `tabopts' 
            
        }
        else if strpos("`outputs'","`x'") > `i'{
        
            outreg2 using "`dirstub'\\stataoutput\tab1", append tex(frag) `tabopts'
    
        }
        else{
        
            outreg2 using "`dirstub'\\stataoutput\tab1", append `tabopts'
    
        }
    Last edited by Mark Mitchell; 10 Oct 2017, 07:20.
Working...
X