Announcement

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

  • Using esttab and estout to Flip Models and Coefficients (tffects nnmatch coefs)

    Hi Stata ninjas,

    I am using estout documentation to develop a table that includes the coefficients from about ~80 "observational experiments" created using teffects nnmatch

    I follow the instructions here http://repec.org/bocode/e/estout/hlp...html#varlabels (you can use Ctrl F and type: "Approach 2: Again run esttab or estout" to find the spot in the documentation.

    It provides the following .do file

    sysuse auto
    eststo model1: quietly reg price weight
    eststo model2: quietly reg price weight mpg
    esttab, se nostar
    matrix C = r(coefs)
    eststo clear
    local rnames : rownames C
    local models : coleq C
    local models : list uniq models
    local i 0
    foreach name of local rnames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
    local ++j
    matrix tmp = C[`i', 2*`j'-1]
    if tmp[1,1]<. {
    matrix colnames tmp = `model'
    matrix b = nullmat(b), tmp
    matrix tmp[1,1] = C[`i', 2*`j']
    matrix se = nullmat(se), tmp
    }
    }
    ereturn post b
    quietly estadd matrix se
    eststo `name'
    }
    esttab, se mtitle noobs
    eststo clear


    when I run this same file except for a teffects command the system produces a name for the coefficient name that will not be processed because it has both symbols and numbers in it. The other reason it might not be accepting the name of the row is they are all the same.

    eststo clear
    eststo: teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb)
    eststo: teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb)
    eststo: teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb)
    esttab, se nostar r2

    matrix C = r(coefs)

    eststo clear

    local rnames : rownames C

    local models : coleq C

    local models : list uniq models

    local i 0

    foreach name of local rnames {
    local ++i
    local j 0
    capture matrix drop b
    capture matrix drop se
    foreach model of local models {
    local ++j
    matrix tmp = C[`i', 2*`j'-1]
    if tmp[1,1]<. {
    matrix colnames tmp = `model'
    matrix b = nullmat(b), tmp
    matrix tmp[1,1] = C[`i', 2*`j']
    matrix se = nullmat(se), tmp
    }
    }
    ereturn post b
    quietly estadd matrix se
    eststo `name'
    }

    . esttab, se mtitle noobs

    because the output of the ATE regression looks like this when it is batched by esttab and even if i write rename command; it will run the regression but ignores the command.





    if anyone can point me in the right direction i would be so grateful for the amount of time it will save : )





    Last edited by Clark Banach; 05 Feb 2021, 20:53.

  • #2
    See https://www.statalist.org/forums/for...erent-commands for how to modify the code and post back if you are unable to figure it out.

    Comment


    • #3
      Hi Andrew,

      Thanks so much for pointing me in the direction of your previous reply. I almost have what I am looking for. Do you know if it is possible to organize the columns created by the following code into a final table where the columns are side by side.

      I am trying to show how the ATE changes as the levels of occupation change. So I run ATE on heavy occupations (hj_hd), dense occupations, general occupations, strong troops and strong infrastructure. If possible I would like to take the results of those tests on the different political parties, using different distances for control groups and arrange them in columns. At the moment I am just copy and pasting them into a word doc, but it would save so much time to output the table with 5 columns and the appropriate column titles.

      I uploaded my database in the off chance you have the time to take a look at this. Thanks again!!

      Code:
      /////2017 ATE of Military Occupation on Voting
      ////General Occupation
      //AFD
      eststo clear
      teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo AFD_far_G, title (General Dummy)
      teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo AFD_prox_G, title (General Dummy)
      teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo AFD_near_G, title (General Dummy)
      //FDP
      teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo FDP_far_G, title (General Dummy)
      teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo FDP_prox_G, title (General Dummy)
      teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo FDP_near_G, title (General Dummy)
      //CDU
      teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo CDU_far_G, title (General Dummy)
      teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo CDU_prox_G, title (General Dummy)
      teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo CDU_near_G, title (General Dummy)
      //SPD
      teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo SPD_far_G, title (General Dummy)
      teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo SPD_prox_G, title (General Dummy)
      teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo SPD_near_G, title (General Dummy)
      //GRN
      teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo GRN_far_G, title (General Dummy)
      teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo GRN_prox_G, title (General Dummy)
      teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo GRN_near_G, title (General Dummy)
      //LNK
      teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo LNK_far_G, title (General Dummy)
      teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo LNK_prox_G, title (General Dummy)
      teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
      eststo LNK_near_G, title (General Dummy)
      
      
      esttab, se nostar r2
      matrix C = r(coefs)
      matrix S = r(stats)
      eststo clear
      local rnames2 : rownames C
      local rnames
      foreach name of local rnames2 {
          local rnames `rnames' `=strtoname("`name'")'
      }
      cap mat rownames C= "`rnames'"
      local models : coleq C
      local models : list uniq models
      local i 0
      foreach name of local rnames {
          local ++i
          local j 0
          capture matrix drop b
          capture matrix drop se
          foreach model of local models {
              local ++j
              matrix tmp = C[`i', 2*`j'-1]
              if tmp[1,1]<. {
                  matrix colnames tmp = `model'
                  matrix b = nullmat(b), tmp
                  matrix tmp[1,1] = C[`i', 2*`j']
                  matrix se = nullmat(se), tmp
              }
          }
          ereturn post b
          quietly estadd matrix se
          eststo `name'
      }
      local rnames2 : rownames S
      local rnames
      foreach name of local rnames2 {
          local rnames `rnames' `=strtoname("`name'")'
      }
      cap mat rownames S= "`rnames'"
      
      local i 0
      foreach name of local snames {
          local ++i
          local j 0
          capture matrix drop b
          foreach model of local models {
              local ++j
              matrix tmp = S[`i', `j']
              matrix colnames tmp = `model'
              matrix b = nullmat(b), tmp
          }
          ereturn post b
          eststo `name'
      }
      esttab, se mtitle noobs compress nonumb
      eststo clear
      Attached Files

      Comment


      • #4
        This is what I get after running your code:

        Code:
         esttab, se noabbrev mtitle noobs compress nonumb
        
        -----------------------
                           .   
        -----------------------
        AFD_far_G    -0.0815***
                    (0.0164)   
        
        AFD_prox_G   -0.0616***
                    (0.0153)   
        
        AFD_near_G   -0.0746***
                    (0.0149)   
        
        FDP_far_G    0.00194   
                   (0.00371)   
        
        FDP_prox_G  -0.00623   
                   (0.00409)   
        
        FDP_near_G  -0.00489   
                   (0.00392)   
        
        CDU_far_G    -0.0121   
                    (0.0141)   
        
        CDU_prox_G   -0.0177   
                    (0.0123)   
        
        CDU_near_G  -0.00563   
                    (0.0120)   
        
        SPD_far_G     0.0397***
                   (0.00987)   
        
        SPD_prox_G    0.0412***
                   (0.00939)   
        
        SPD_near_G    0.0323***
                   (0.00927)   
        
        GRN_far_G     0.0127*  
                   (0.00603)   
        
        GRN_prox_G   0.00975   
                   (0.00864)   
        
        GRN_near_G    0.0164*  
                   (0.00801)   
        
        LNK_far_G     0.0365***
                   (0.00884)   
        
        LNK_prox_G    0.0284** 
                   (0.00910)   
        
        LNK_near_G    0.0315***
                   (0.00903)   
        -----------------------
        Standard errors in parentheses
        * p<0.05, ** p<0.01, *** p<0.001
        Do you mean that you want a column for each party? For example, AFD, FDP,..., LNK.

        Comment


        • #5
          Awesome!

          That is what the code is supposed to do. I wanted a column for each of the next tests. I have dummies for varying strengths of occupation. So I am running the experiment on all political parties using the varying strength of occupation as the treatment. So ATE 1 - 5 are as follows:

          ATE1 - general occupation
          ATE2 - dense occupation
          ATE3 - heavy occupation
          ATE4 - heavy troops
          ATE5 - heavy infrastructure

          So I have 5 more repetitions of the code I sent where the only variation is the treatment variable. I would like to line them up side by side to save time. See the picture below. I can send the code with all variations of the column if you need, but I thought it would be overly repetitious.
          Last edited by Clark Banach; 10 Feb 2021, 01:55.

          Comment


          • #6
            OK, got it. You want to make use of estimates save in the intermediate, and at the end, bring all the results together with estimates use and eststo. Here is an example based on your code (I run the same commands again, where the repetition mimics a new test).

            Code:
            /////2017 ATE of Military Occupation on Voting
            ////General Occupation
            //AFD
            preserve
            eststo clear
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_far_G, title (General Dummy)
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_prox_G, title (General Dummy)
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_near_G, title (General Dummy)
            //FDP
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_far_G, title (General Dummy)
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_prox_G, title (General Dummy)
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_near_G, title (General Dummy)
            //CDU
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_far_G, title (General Dummy)
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_prox_G, title (General Dummy)
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_near_G, title (General Dummy)
            //SPD
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_far_G, title (General Dummy)
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_prox_G, title (General Dummy)
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_near_G, title (General Dummy)
            //GRN
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_far_G, title (General Dummy)
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_prox_G, title (General Dummy)
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_near_G, title (General Dummy)
            //LNK
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_far_G, title (General Dummy)
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_prox_G, title (General Dummy)
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_near_G, title (General Dummy)
            
            
            esttab, se nostar r2
            matrix C = r(coefs)
            matrix S = r(stats)
            eststo clear
            local rnames2 : rownames C
            local rnames
            foreach name of local rnames2 {
                local rnames `rnames' `=strtoname("`name'")'
            }
            cap mat rownames C= "`rnames'"
            local models : coleq C
            local models : list uniq models
            local i 0
            foreach name of local rnames {
                local ++i
                local j 0
                capture matrix drop b
                capture matrix drop se
                foreach model of local models {
                    local ++j
                    matrix tmp = C[`i', 2*`j'-1]
                    if tmp[1,1]<. {
                        matrix colnames tmp = `model'
                        matrix b = nullmat(b), tmp
                        matrix tmp[1,1] = C[`i', 2*`j']
                        matrix se = nullmat(se), tmp
                    }
                }
                ereturn post b
                quietly estadd matrix se
                eststo `name'
            }
            local rnames2 : rownames S
            local rnames
            foreach name of local rnames2 {
                local rnames `rnames' `=strtoname("`name'")'
            }
            cap mat rownames S= "`rnames'"
            
            local i 0
            foreach name of local snames {
                local ++i
                local j 0
                capture matrix drop b
                foreach model of local models {
                    local ++j
                    matrix tmp = S[`i', `j']
                    matrix colnames tmp = `model'
                    matrix b = nullmat(b), tmp
                }
                ereturn post b
                eststo `name'
            }
            esttab, se mtitle noobs compress nonumb
            est save res1, replace
            restore, preserve
            eststo clear
            /////2017 ATE of Military Occupation on Voting
            ////Some New Test
            //AFD
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_far_G, title (General Dummy)
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_prox_G, title (General Dummy)
            teffects nnmatch (percentageafd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo AFD_near_G, title (General Dummy)
            //FDP
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_far_G, title (General Dummy)
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_prox_G, title (General Dummy)
            teffects nnmatch (percentagefdp ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo FDP_near_G, title (General Dummy)
            //CDU
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_far_G, title (General Dummy)
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_prox_G, title (General Dummy)
            teffects nnmatch (percentagecdu ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo CDU_near_G, title (General Dummy)
            //SPD
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_far_G, title (General Dummy)
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_prox_G, title (General Dummy)
            teffects nnmatch (percentagespd ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo SPD_near_G, title (General Dummy)
            //GRN
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_far_G, title (General Dummy)
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_prox_G, title (General Dummy)
            teffects nnmatch (percentagegreen ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo GRN_near_G, title (General Dummy)
            //LNK
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==3)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_far_G, title (General Dummy)
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==2)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_prox_G, title (General Dummy)
            teffects nnmatch (percentagelinke ln_jekm ln_inc_per turnout) (hj_hb) if (year==2017)&((hj_hb==1)|(hj_hb==0&dist_ind==1)), ematch(dens_ind) dtolerance(1) biasadj(ln_inc_per ln_jekm turnout)
            eststo LNK_near_G, title (General Dummy)
            
            
            esttab, se nostar r2
            matrix C = r(coefs)
            matrix S = r(stats)
            eststo clear
            local rnames2 : rownames C
            local rnames
            foreach name of local rnames2 {
                local rnames `rnames' `=strtoname("`name'")'
            }
            cap mat rownames C= "`rnames'"
            local models : coleq C
            local models : list uniq models
            local i 0
            foreach name of local rnames {
                local ++i
                local j 0
                capture matrix drop b
                capture matrix drop se
                foreach model of local models {
                    local ++j
                    matrix tmp = C[`i', 2*`j'-1]
                    if tmp[1,1]<. {
                        matrix colnames tmp = `model'
                        matrix b = nullmat(b), tmp
                        matrix tmp[1,1] = C[`i', 2*`j']
                        matrix se = nullmat(se), tmp
                    }
                }
                ereturn post b
                quietly estadd matrix se
                eststo `name'
            }
            local rnames2 : rownames S
            local rnames
            foreach name of local rnames2 {
                local rnames `rnames' `=strtoname("`name'")'
            }
            cap mat rownames S= "`rnames'"
            
            local i 0
            foreach name of local snames {
                local ++i
                local j 0
                capture matrix drop b
                foreach model of local models {
                    local ++j
                    matrix tmp = S[`i', `j']
                    matrix colnames tmp = `model'
                    matrix b = nullmat(b), tmp
                }
                ereturn post b
                eststo `name'
            }
            esttab, se mtitle noobs compress nonumb
            estimates save res2, replace
            eststo clear
            estimates use res1
            eststo res1
            estimates use res2
            eststo res2
            esttab res1 res2 res1 res2, mtitles("Gen. Occupation" "Other 1" "Other 2" "Other 3") nonumb noobs
            Res.:

            Code:
            
            ----------------------------------------------------------------------------
                         Gen. Occup~n         Other 1         Other 2         Other 3   
            ----------------------------------------------------------------------------
            AFD_far_G         -0.0828***      -0.0828***      -0.0828***      -0.0828***
                              (-5.03)         (-5.03)         (-5.03)         (-5.03)   
            
            AFD_prox_G        -0.0615***      -0.0615***      -0.0615***      -0.0615***
                              (-4.01)         (-4.01)         (-4.01)         (-4.01)   
            
            AFD_near_G        -0.0748***      -0.0748***      -0.0748***      -0.0748***
                              (-5.00)         (-5.00)         (-5.00)         (-5.00)   
            
            FDP_far_G         0.00243         0.00243         0.00243         0.00243   
                               (0.65)          (0.65)          (0.65)          (0.65)   
            
            FDP_prox_G       -0.00612        -0.00612        -0.00612        -0.00612   
                              (-1.50)         (-1.50)         (-1.50)         (-1.50)   
            
            FDP_near_G       -0.00485        -0.00485        -0.00485        -0.00485   
                              (-1.23)         (-1.23)         (-1.23)         (-1.23)   
            
            CDU_far_G         -0.0107         -0.0107         -0.0107         -0.0107   
                              (-0.75)         (-0.75)         (-0.75)         (-0.75)   
            
            CDU_prox_G        -0.0175         -0.0175         -0.0175         -0.0175   
                              (-1.42)         (-1.42)         (-1.42)         (-1.42)   
            
            CDU_near_G       -0.00566        -0.00566        -0.00566        -0.00566   
                              (-0.47)         (-0.47)         (-0.47)         (-0.47)   
            
            SPD_far_G          0.0399***       0.0399***       0.0399***       0.0399***
                               (4.02)          (4.02)          (4.02)          (4.02)   
            
            SPD_prox_G         0.0410***       0.0410***       0.0410***       0.0410***
                               (4.37)          (4.37)          (4.37)          (4.37)   
            
            SPD_near_G         0.0323***       0.0323***       0.0323***       0.0323***
                               (3.47)          (3.47)          (3.47)          (3.47)   
            
            GRN_far_G          0.0127*         0.0127*         0.0127*         0.0127*  
                               (2.09)          (2.09)          (2.09)          (2.09)   
            
            GRN_prox_G        0.00971         0.00971         0.00971         0.00971   
                               (1.12)          (1.12)          (1.12)          (1.12)   
            
            GRN_near_G         0.0164*         0.0164*         0.0164*         0.0164*  
                               (2.03)          (2.03)          (2.03)          (2.03)   
            
            LNK_far_G          0.0359***       0.0359***       0.0359***       0.0359***
                               (4.04)          (4.04)          (4.04)          (4.04)   
            
            LNK_prox_G         0.0285**        0.0285**        0.0285**        0.0285** 
                               (3.13)          (3.13)          (3.13)          (3.13)   
            
            LNK_near_G         0.0317***       0.0317***       0.0317***       0.0317***
                               (3.49)          (3.49)          (3.49)          (3.49)   
            ----------------------------------------------------------------------------
            t statistics in parentheses
            * p<0.05, ** p<0.01, *** p<0.001
            Last edited by Andrew Musau; 10 Feb 2021, 05:02.

            Comment


            • #7
              Andrew,

              Real heros don't wear capes. Your help has saved me so much time. Thank you so much. You wouldn't happen to know a quick way I could modify the normal code I use to spit out and .rtf document so that this whole magnificent beast is out to a publishable table?

              Code:
              esttab using 09_13_Bau_Density.rtf, rtf mtitle nonumbers nodepvars compress label nocons se ar2 star(* 0.10 ** 0.05 *** 0.01) page replace title(Federal Election 2009-13)

              Here is the final output.

              Code:
              --------------------------------------------------------------------------------------------
                           Gen. Occup~n    Dense Occu~n    Heavy Occu~n    Heavy Troops    Heavy Infr~e   
              --------------------------------------------------------------------------------------------
              AFD_far_G         -0.0372***      -0.0542***      -0.0975***      -0.0815***      -0.0506***
                                (-3.36)         (-4.49)         (-5.83)         (-6.03)         (-3.78)   
              
              AFD_prox_G        -0.0224**       -0.0331**       -0.0746***      -0.0637***      -0.0257*  
                                (-2.84)         (-3.08)         (-4.99)         (-5.98)         (-2.17)   
              
              AFD_near_G        -0.0257**       -0.0316**       -0.0883***      -0.0652***      -0.0277*  
                                (-3.17)         (-3.10)         (-5.88)         (-6.16)         (-2.46)   
              
              FDP_far_G         0.00768***      0.00662**      -0.00259         0.00426         0.00698** 
                                 (3.59)          (2.94)         (-0.63)          (1.29)          (2.88)   
              
              FDP_prox_G       -0.00298        -0.00226        -0.00843*       -0.00428        -0.00171   
                                (-1.91)         (-0.97)         (-2.05)         (-1.48)         (-0.70)   
              
              FDP_near_G       -0.00180        -0.00216        -0.00785        -0.00334       -0.000995   
                                (-0.92)         (-0.99)         (-1.94)         (-1.18)         (-0.43)   
              
              CDU_far_G         -0.0265         -0.0266*       -0.00755        -0.00964         -0.0266*  
                                (-1.83)         (-2.12)         (-0.52)         (-0.73)         (-2.09)   
              
              CDU_prox_G        -0.0244***      -0.0283***      -0.0106         -0.0123         -0.0337***
                                (-4.45)         (-4.61)         (-0.89)         (-1.38)         (-5.37)   
              
              CDU_near_G        -0.0107*        -0.0139*      -0.000645         0.00228         -0.0233***
                                (-2.13)         (-2.47)         (-0.06)          (0.27)         (-4.04)   
              
              SPD_far_G          0.0207**        0.0295***       0.0459***       0.0427***       0.0235** 
                                 (3.05)          (4.05)          (4.88)          (4.99)          (3.04)   
              
              SPD_prox_G         0.0252***       0.0319***       0.0431***       0.0464***       0.0255***
                                 (7.85)          (5.19)          (4.78)          (7.57)          (3.92)   
              
              SPD_near_G         0.0209***       0.0259***       0.0352***       0.0386***       0.0164*  
                                 (4.62)          (4.29)          (4.00)          (6.50)          (2.57)   
              
              GRN_far_G         0.00774***       0.0106***       0.0154*         0.0118*        0.00982** 
                                 (3.34)          (3.57)          (1.97)          (2.21)          (2.74)   
              
              GRN_prox_G        0.00334*        0.00583          0.0128         0.00893         0.00544   
                                 (2.22)          (1.51)          (1.40)          (1.94)          (1.27)   
              
              GRN_near_G        0.00367         0.00723*         0.0197*         0.0114*        0.00818*  
                                 (1.41)          (2.11)          (2.26)          (2.57)          (2.23)   
              
              LNK_far_G          0.0272***       0.0341***       0.0479***       0.0368***       0.0357***
                                 (4.17)          (5.55)          (5.30)          (4.82)          (5.53)   
              
              LNK_prox_G         0.0179***       0.0229***       0.0368***       0.0274***       0.0251***
                                 (5.74)          (4.89)          (4.23)          (4.42)          (5.15)   
              
              LNK_near_G         0.0132***       0.0151**        0.0412***       0.0206***       0.0245***
                                 (3.56)          (3.26)          (4.79)          (3.39)          (5.15)   
              --------------------------------------------------------------------------------------------
              t statistics in parentheses
              * p<0.05, ** p<0.01, *** p<0.001
              
              . 
              end of do-file
              .

              Comment


              • #8
                nevermind. got it. thanks!!!

                Comment


                • #9
                  Dear friends, I wondered if there was a command dealing with the treatment effects on panel data.

                  Comment

                  Working...
                  X