Announcement

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

  • return all estimated coefficients for all regressions in the bootstrap?

    Dear All, Suppose that I do the following bootstrap (please ssc install reghdfe)
    Code:
    set seed 1234567
    capture program drop sobel
    program define sobel, rclass
        reghdfe lRDSpendSumRatio co ROA LSize LLev LTobinQ Revenue Lsharebymanager LZvalue, a(ind1 year) 
        local a = _b[co]
        reghdfe Fncskew lRDSpendSumRatio co ret_m sigma turn_d lbsize lsize lmb lev roa labacc, a(ind1 year)    
        local b = _b[co]   
        return scalar s = `a'*`b'
        exit
    end
    
    bootstrap s = r(s), reps(100): sobel
    In addition to `s', I wonder if I can obtain all the estimated coefficients from these two regressions? Thanks.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Yes, but not easily, I think. You would need, inside program sobel, to add code to return each of the regression coefficients as a scalar. Then you would need to list capture all of those scalars in the -bootstrap- command, and also specify the -saving()- option to the -bootstrap- prefix (after the command before the colon). To keep it from being a long list of -return scalar- statements, probably the simplest way is to create local macros each containing the list of variables from one of the regressions. Then after each regression, you can loop over that variable list saving a scalar whose name matches that of the variable whose coefficient you are processing.

    Comment


    • #3
      Dear Clyde, Thanks for the reply. I know that I can do that one by one (a stupid but straightforward way). Indeed, I was expecting a simple way to this problem, but seem no such method is available.

      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        River: I often like to use Mata matrixes to accumulate bootstrap results. Here is a quick-and-dirty approach that might give you an idea. In a more elegant program you'd want to be more careful about definitions, use of locals, etc. but this code should give you the basic idea of embedding Mata accumulators inside your Stata program.

        Code:
        set seed 1234567
        capture program drop sobel
         
        program define sobel, rclass  
        reg y1 x
        mata c1=c1\st_matrix("e(b)")      
        local a = _b[x]   
        reg y2 x   
        mata c2=c2\st_matrix("e(b)")      
        local b = _b[x]        
        return scalar s = `a'*`b'     
        exit
        end  
        
        mata c1=J(0,2,.)
        mata c2=J(0,2,.)
        
        bootstrap s = r(s), reps(100): sobel

        Comment


        • #5
          What about something like this:
          Code:
           
           clear all sysuse nlswork, clear capture program drop twools program twools, eclass     reghdfe  ln_wage tenure ttl_exp, abs(idcode)     matrix b1=e(b)     reghdfe  ln_wage age not_smsa, abs(idcode)     matrix b2=e(b)     matrix coleq b1=eq1     matrix coleq b2=eq2     matrix b=b1,b2     ereturn post b end  bootstrap:twools
          Of course, that will need to be "cleaned" to fit your purposes.
          Fernando

          Comment


          • #6
            Dear John, Thanks for the suggestion. I will give it a try.
            Ho-Chuan (River) Huang
            Stata 19.0, MP(4)

            Comment


            • #7
              Dear FernandoRios, Thanks for the suggestion. It seems to work well as follows.
              Code:
              . set linesize 80
              
              . 
              . webuse nlswork, clear 
              (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
              
              .  
              . capture program drop twools 
              
              . program define twools, eclass     
                1.   reghdfe ln_wage tenure ttl_exp, abs(idcode)     
                2.   matrix b1=e(b)     
                3.   reghdfe ln_wage age not_smsa, abs(idcode)     
                4.   matrix b2=e(b)     
                5.   matrix coleq b1=eq1     
                6.   matrix coleq b2=eq2     
                7.   matrix b=b1,b2     
                8.   ereturn post b 
                9. end  
              
              .  
              . bootstrap: twools
              (running twools on estimation sample)
              
              Warning:  Because twools is not an estimation command or does not set
                        e(sample), bootstrap has no way to determine which observations are
                        used in calculating the statistics and so assumes that all
                        observations are used.  This means that no observations will be
                        excluded from the resampling because of missing values or other
                        reasons.
              
                        If the assumption is not true, press Break, save the data, and drop
                        the observations that are to be excluded.  Be sure that the dataset
                        in memory contains only the relevant data.
              
              Bootstrap replications (50)
              ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
              ..................................................    50
              
              Bootstrap results                               Number of obs     =     28,534
                                                              Replications      =         50
              
              ------------------------------------------------------------------------------
                           |   Observed   Bootstrap                         Normal-based
                           |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              eq1          |
                    tenure |   .0123934   .0010275    12.06   0.000     .0103796    .0144073
                   ttl_exp |   .0245398   .0008223    29.84   0.000     .0229281    .0261515
                     _cons |   1.486153   .0040422   367.66   0.000     1.478231    1.494076
              -------------+----------------------------------------------------------------
              eq2          |
                       age |   .0182463   .0003785    48.21   0.000     .0175045    .0189881
                  not_smsa |   -.106322    .012005    -8.86   0.000    -.1298514   -.0827926
                     _cons |   1.177102   .0103384   113.86   0.000     1.156839    1.197365
              ------------------------------------------------------------------------------
              
              . 
              end of do-file
              But, does the "Warning" matter?
              Ho-Chuan (River) Huang
              Stata 19.0, MP(4)

              Comment


              • #8
                I do not think so, unless you are using different samples for each regression. Probably other people may provide you better suggestion in modifying the program to add the esample option, but this is the easiest way to do what you want.
                Best
                Fernando

                Comment


                • #9
                  Dear FernandoRios, Thanks again for the reply.
                  Ho-Chuan (River) Huang
                  Stata 19.0, MP(4)

                  Comment

                  Working...
                  X