benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

missing line when output Matrix to RTF-file using esttab #39

Closed dreistein543 closed 2 years ago

dreistein543 commented 2 years ago

When I try to output bootstrap results stored in a matrix, the line between table head-row and content-row misses, which can display well in Stata.

// net install sgmediation2, from("https://tdmize.github.io/data/sgmediation2")  // install third-party command if you need
use "http://www.stata-press.com/data/r16/nlswork.dta",clear
glo y ln_wage 
glo x hours    
glo m race 

bootstrap r(ind_eff) , reps(20): sgmediation2 ${y}, mv(${m}) iv(${x})
cap mat drop Boot
mat Boot = [e(b)',e(ci_bc)']
mat rownames Boot = "$x -> $m -> $y" 
mat colnames Boot = "Coef Path" "95% Confidence Interval"
esttab mat(Boot), replace nomtitle // correct
---------------------------------------------------
                Coef Path 95% Confid~l 95% Confid~l
---------------------------------------------------       // this line exists
hours -> r~e    -.0003705    -.0004244    -.0002811
---------------------------------------------------

esttab mat(Boot) using ~/mytable.rtf, replace nomtitle // incorrect
截屏2022-04-11 15 07 31

However, if I input a matrix manually, esttab works well.

cap mat drop Test
mat Test = (1,2,3,4 \ 5,6,7,8)
mat rownames Test = "Row Name"
mat colnames Test = "Col Name"
esttab mat(Test), nomtitle // correct
----------------------------------------------------------------
                 Col Name     Col Name     Col Name     Col Name
---------------------------------------------------------------- // exist
Row Name                1            2            3            4
Row Name                5            6            7            8
----------------------------------------------------------------
esttab mat(Test) using ~/mytable.rtf, replace nomtitle // correct
截屏2022-04-11 15 13 39
dreistein543 commented 2 years ago

as for the issue of output bootstrap results, I have another more mature approach, but this problem may occur in other situations.

benjann commented 2 years ago

The missing line is due to the fact that the table body only contains a single row. The subroutine adding the lines does not seem to be prepared for this situation. I'll see whether I can fix this.

benjann commented 2 years ago

I now looked into that. It would be quite an effort to cover this special case. I would prefer not to touch this.

dreistein543 commented 2 years ago

OK, as you said, this issue occurs only when the table body containing a single row, which is just a very extreme situation. it seems worthless to fix it at a cost of much effort.

thank you for your work.

benjann commented 2 years ago

Never mind. I found a relatively simple solution to fix the problem and posted an update. The line will now be printed also if the table body only contains a single line.

NilsEnevoldsen commented 2 years ago

@benjann You can re-close this issue now that you've addressed it.