Announcement

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

  • How to display different reference categories when stacking models using -estout-?

    Hi,

    I am using -estout- (available from SSC) to stack models but since my independent variable is the same using the -, refcat()- option isn't working. I know why this isn't working, but would anyone know if there's a workaround? I would like a table like the following:

    Code:
    -------------------------
                          (1)  
    -------------------------
    All                      
    
    weight              2.044
                      (0.377)
    
    Domestic
    
    weight              2.995
                      (0.466)
    
    Foreign      
    
    weight              5.362
                      (0.629)
    -------------------------
    N                        
    -------------------------
    Here's the code that I currently have:

    Code:
    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
    
    sysuse auto, clear
    
    * ssc install estout, replace
    
    eststo m0: qui reg price weight
    eststo m1: qui reg price weight if foreign == 0
    eststo m2: qui reg price weight if foreign == 1
    
    eststo mstack: appendmodels m0 m1 m2
    
    esttab mstack, keep(weight) se nostar ///
    refcat(weight "All" weight "Domestic" weight "Foreign", nolabel)
    Last edited by Aaditya Dar; 21 May 2016, 05:37.

  • #2
    Maybe I should rephrase my question to ask how can one stack models if one is running regressions on sub samples of the data. For example, if I run three regressions like the following:

    Code:
    sysuse auto, clear
    reg price weight
    reg price weight if foreign == 0
    reg price weight if foreign == 1
    is it possible to create a table like

    Code:
    -------------------------
                          (1)  
    -------------------------
    All                      
    
    weight              2.044
                      (0.377)
    -------------------------
    N                  74      
    -------------------------
    
    foreign == 0 / Domestic
    
    weight              2.995
                      (0.466)
    -------------------------
    N                    52    
    -------------------------
    
    foreign == 1 / Foreign
    
    weight              5.362
                      (0.629)
    -------------------------
    N                    22      
    -------------------------

    Comment


    • #3
      I think you need to define a different independent variable for each row. For example:
      Code:
      gen weight1 = weight
      gen weight2 = weight
      gen weight3 = weight
      
      reg price weight1
      reg price weight2 if foreign==0
      reg price weight3 if foreign==1
      Then `appendmodels` should do the job.

      Comment

      Working...
      X