Announcement

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

  • Combine features of outreg2 and putdocx command

    Dear Statalisters,

    I usually run the outreg2 command to export regression output to Word. Recently, I've been exploring the options of the putdocx command for saving results and output to Word files using codes similar to this one:


    Code:
    putdocx begin
    
    regress mpg gear_ratio turn foreign, noheader cformat(%9.3f)
    
    matrix list r(table)
    matrix rtable = r(table)'
    matrix r_table = rtable[1...,1], rtable[1...,5..6]
    
    putdocx table Example_Putdocx3 = (1,2), border(all, nil) width(4) halign(center) note("Note: standard errors are in parentheses") layout(autofitcontents)
    putdocx table Example_Putdocx3(1,1)=("mpg"), halign(right) colspan(2) border(top) border(bottom)
    
    local row 1
    local vari 1
    
    foreach x in gear_ratio turn foreign _cons {
    putdocx table Example_Putdocx3(`row',.), addrows(2)
    
    local b: display %9.3f rtable[`vari',1]
    local se: display %9.3f rtable[`vari',2]
    local ++vari
    local ++row
    putdocx table Example_Putdocx3(`row',1) = ("`x'"), halign(right)
    putdocx table Example_Putdocx3(`row',2) = ("`b'"), halign(right)
    local ++row
    local se = strtrim("`se'")
    putdocx table Example_Putdocx3(`row',2) = ("(`se')"), halign(right)
    }
    
    putdocx table Example_Putdocx3(`row',.), addrows(2)
    
    local ++row
    putdocx table Example_Putdocx3(`row',1) = ("N"), border(top) halign(right)
    putdocx table Example_Putdocx3(`row',2) = (e(N)), border(top) halign(right)
    local ++row
    local r2: display %9.3f e(r2)
    putdocx table Example_Putdocx3(`row',1) = ("R2"), halign(right) border(bottom)
    putdocx table Example_Putdocx3(`row',2) = (`r2'), halign(right) border(bottom)
    
    
    putdocx save Example_Putdocx.docx, append

    Creating this kind of code for all of the regressions that I have to run is not very user-friendly. However, the putdocx command has some interesting features that, as far as I know, cannot be included in the outreg2 command. For example, cells can be fitted to content in Word (see option layout(autofitcontents) in bold), text can be aligned to the right of a cell (see option: halign(right) in bold) and a table can be aligned to the center of the page (see option: halign(center) in bold). Does anyone know if and how to include these features in the outreg2 command?


    Thank you in advance.


    Kind regards,

    ​​​​​​​
    Eline




  • #2
    Short answer is that I don't know. But a few comments may help.

    outreg2 (SSC, as you are asked to explain) is a community-contributed command by Roy Wada. He is not a member here but has an email address. outreg2 hasn't been updated publicly since 2014. Only Roy can say what might happen to it in future. But outreg2 works with Stata 7 up. It would be a very radical departure from his past style to add features dependent on more recent additions to Stata, but he might fork outreg2 or rewrite it as something else. You need to ask him directly.

    Otherwise, apart from writing your own more general code, there may be scope to do this with other commands, but I can't say more.

    Comment

    Working...
    X