Announcement

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

  • Outreg2 addstats addtext - want to report S.E. value of joint coefficients within parenthesis at the bottom of the table

    Hello Statalist,

    I want to report joint coefficients and standard errors at the bottom of a regression table using outreg2, and I cannot find a way to add parentheses to the standard errors. I've tried with both addtext and addstat, displaying the local in several ways. I want to export the standard errors as they appear in the top/automatic table with the regression output generated by outreg2, with the S.E. with 2 decimals and within parentheses. See in the screenshot below that the closing parenthesis is not taken properly.
    I'm showing below a simplified version, but in my code, I actually run hundreds of regressions which I first append using outreg, save as dta, and then combine sheets through a loop that combines Excel sheets into one spreadsheet. That is the reason why I export in two steps and I'd prefer to keep that, if possible.


    -------------------------------------------------------------------
    *ssc install dataex
    clear
    sysuse auto

    reghdfe price headroom length, nocons absorb(foreign)

    qui lincom headroom + length
    local Lincom : di %9.2f `r(se)'

    di "`Lincom'"

    * Convert to string
    local Lincom: di "(" string(`r(se)', "%9.2f") + ")"
    di "`Lincom'"

    local Lincom2: di "`Lincom'"
    di "`Lincom2'"

    local Lincom3: di "(`r(se)')"
    di "`Lincom3'"


    *outreg2 using "$results/test", replace dta dec(2) pdec(2) adds(Joint SE, "`Lincom'", Joint SE, `Lincom', Joint SE, "`Lincom2'", Joint SE, `Lincom2', Joint SE, "`Lincom3'", Joint SE, `Lincom3')

    outreg2 using "$results/test", replace dta dec(2) pdec(2) addtext(Joint SE, "`Lincom'", Joint SE, `Lincom', Joint SE, "`Lincom2'", Joint SE, `Lincom2', Joint SE, "`Lincom3'", Joint SE, `Lincom3')

    preserve
    use "$results/test_dta", clear
    export excel using "$results/test.xlsx", replace
    restore

    -------------------------------------------------------------------


    Click image for larger version

Name:	Screenshot 2024-02-09 at 11.08.35.png
Views:	1
Size:	55.0 KB
ID:	1742635


    Your help will be much appreciated

    Many thanks

    Maria

  • #2
    outreg2 and reghdfe are from SSC (FAQ Advice #12). You need compound double quotes. This may take some getting used to.

    Code:
    clear
    sysuse auto
    reghdfe price headroom length, nocons absorb(foreign)
    qui lincom headroom + length
    local Lincom= "(" + string(`r(se)', "%9.2f") + ")"
    outreg2 using "results", replace dta dec(2) pdec(2) addtext(Joint SE, `""`Lincom'""')
    Res.:

    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	11.7 KB
ID:	1742653

    Comment


    • #3
      It worked! Thanks so much Andrew!

      Comment

      Working...
      X