Announcement

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

  • Add scalar to balance table using esttab

    I am working on generating a simple balance table, which tests equality of variables across a common treatment & then adds the result of a joint significance test below. I am using the esttab package to export to latex. Everything works as intended, except that the stored p-value for the joint-test does not appear. Example code below:

    Code:
    clear all
    ssc install estout
    sysuse auto
    
    eststo diffs: estpost ttest price mpg weight length, by(foreign)
    reg foreign price mpg weight length
    testparm price mpg weight length
    estadd scalar joint_test = `r(p)'
    
    esttab using "balance.tex", replace ///
          star(* 0.10 ** 0.05 *** 0.01) label booktabs nonum gaps noobs compress ///
          cells("mu_1(fmt(2)) mu_2(fmt(2))  p(fmt(3)) count(fmt(0))") ///
          collabels("Control" "Treatment" "p-value" "N") ///
          scalars("joint_test Joint significance test") sfmt(3)
    Output:

    Click image for larger version

Name:	output.png
Views:	1
Size:	7.2 KB
ID:	1708403

  • #2
    regress being an estimation command overwrites the previous estimates in memory.

    Code:
    clear all
    *ssc install estout
    sysuse auto
    
    eststo diffs: estpost ttest price mpg weight length, by(foreign)
    reg foreign price mpg weight length
    testparm price mpg weight length
    local joint_test = `r(p)'
    est restore diffs
    estadd scalar joint_test = `joint_test'
    
    esttab, replace ///
          star(* 0.10 ** 0.05 *** 0.01) label nonum gaps noobs compress ///
          cells("mu_1(fmt(2)) mu_2(fmt(2))  p(fmt(3)) count(fmt(0))") ///
          collabels("Control" "Treatment" "p-value" "N") ///
          scalars("joint_test Joint significance test") sfmt(3)
    Res.:

    Code:
    . esttab, replace ///
    >       star(* 0.10 ** 0.05 *** 0.01) label nonum gaps noobs compress ///
    >       cells("mu_1(fmt(2)) mu_2(fmt(2))  p(fmt(3)) count(fmt(0))") ///
    >       collabels("Control" "Treatment" "p-value" "N") ///
    >       scalars("joint_test Joint significance test") sfmt(3)
    
    --------------------------------------------------------
                                                            
                       Control Treatment   p-value         N
    --------------------------------------------------------
    Price              6072.42   6384.68     0.680        74
    
    Mileage (mpg)        19.83     24.77     0.001        74
    
    Weight (lbs.)      3317.12   2315.91     0.000        74
    
    Length (in.)        196.13    168.55     0.000        74
    --------------------------------------------------------
    Joint signific~t     0.000                              
    -------------------------------------------------------

    Comment


    • #3
      An alternative:

      Code:
      clear all
      ssc install estout
      sysuse auto
      
      eststo diffs: estpost ttest price mpg weight length, by(foreign)
      reg foreign price mpg weight length
      testparm price mpg weight length
      estadd scalar joint_test = `r(p)' : diffs
      
      esttab diffs using "balance.tex", replace ///
            star(* 0.10 ** 0.05 *** 0.01) label booktabs nonum gaps noobs compress ///
            cells("mu_1(fmt(2)) mu_2(fmt(2))  p(fmt(3)) count(fmt(0))") ///
            collabels("Control" "Treatment" "p-value" "N") ///
            scalars("joint_test Joint significance test") sfmt(3)
      The first change, adding ": diffs" to the estadd command, ensures that this scalar is added to estimation "diffs" instead of the estimation created by the regress.

      The second change is unnecessary, but I think it is a good habit to always specify what estimations you are esttabbing, whether that's a named estimation, or "*", or even ".". In this case it works out fine since esttab prefers estimation results that are eststored.

      Comment


      • #4
        Ah, derp- thank you Andrew!

        Nils - thanks also for the alternative response. I wasn't aware that you could assign to a specific estimation instead of the current one- that's great to know, and I totally agree, always safer to be explicit!

        Comment

        Working...
        X