Announcement

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

  • esttab command: How to display the number of observations for each model when stacking models

    Hi all,

    I am creating a series of regression models that are run on sub-samples of the data, where each column corresponds to a different independent variable that is run on the same set of sub-samples. I am using "esttab" and the "appendmodels" program written by Ben Jann, and stacking the models using refcat().

    More precisely, here is the code. First, install the estout command and create the "appendmodels" program, as written by Ben Jann:
    Code:
    ssc install estout, replace
    capt prog drop appendmodels
    *! version 1.0.0  14aug2007  Ben Jann
    program appendmodels, eclass
    // using first equation of model
     syntax namelist
     tempname b V tmp
     foreach name of local namelist {
         qui est restore `name'
         mat `tmp' = e(b)
         local eq1: coleq `tmp'
         gettoken eq1 : eq1
         mat `tmp' = `tmp'[1,"`eq1':"]
         local cons = colnumb(`tmp',"_cons")
         if `cons'<. & `cons'>1 {
             mat `tmp' = `tmp'[1,1..`cons'-1]
         }
         mat `b' = nullmat(`b') , `tmp'
         mat `tmp' = e(V)
         mat `tmp' = `tmp'["`eq1':","`eq1':"]
         if `cons'<. & `cons'>1 {
             mat `tmp' = `tmp'[1..`cons'-1,1..`cons'-1]
         }
         capt confirm matrix `V'
         if _rc {
             mat `V' = `tmp'
         }
         else {
             mat `V' = ///
             ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
             ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
        }
    }
    local names: colfullnames `b'
    mat coln `V' = `names'
    mat rown `V' = `names'
    eret post `b' `V'
    eret local cmd "whatever"
    end
    Then, running the models and using esttab to generate the output:
    Code:
    sysuse auto, clear
    
    gen weight_nf = weight if foreign == 0
    gen weight_f  = weight if foreign == 1
    
    gen headroom_nf = headroom if foreign == 0
    gen headroom_f  = headroom if foreign == 1
    
    eststo price_nf: reg price weight_nf headroom_nf if foreign==0
    eststo price_f:  reg price weight_f  headroom_f  if foreign==1
    
    eststo gear_nf: reg gear_ratio weight_nf headroom_nf if foreign==0
    eststo gear_f:  reg gear_ratio weight_f  headroom_f  if foreign==1
    
    eststo price_all: appendmodels price_nf price_f
    eststo gear_all:  appendmodels gear_nf  gear_f
    
    esttab price_all gear_all, keep(weight* headroom*) se ///
        title(Table 1) ///
        star(* 0.10 ** 0.05 *** 0.01) ///
        refcat(weight_nf "Panel A: Non-Foreign" weight_f "Panel B: Foreign", nolabel) label
    What I want, though, it that both panels display the number of observations used. Essentially, using the names from the code above, this means adding one row at the end of "Panel A: Non-Foreign" and another at the end of "Panel B: Foreign". Could someone help me with that?

    Also, I am using eststo and esttab for this, but would anyone recommend using other commands, such as outreg2?

    Thank you,
    Sergio

  • #2
    Hi, I know this was a while ago but just wanted to see if you ever figured this out? Or if anyone else knows a solution to this?

    Comment


    • #3
      See https://www.statalist.org/forums/for...rs-with-esttab

      Comment

      Working...
      X