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

Can't rename variable in a three-level mixed-effects model #15

Closed ebardelli closed 5 years ago

ebardelli commented 6 years ago

Hi!

estout fails with an error when trying to rename a variable in a three-level mixed-effect model.

See example below from example 4 for melogit:

use http://www.stata-press.com/data/r15/towerlondon, clear
melogit dtlm difficulty i.group || family: || subject: , or
esttab, rename(difficulty "Test rename")

estout fails with the following error:

equation / not found
r(303);

The error seems to be caused by line 2622 in estout.ado.

Replacing it with

capture mat `tmp' = `bc'[`"`eq':"',1]
if _rc != 0 continue

seems to fix the issue.

chrjmeyer commented 6 years ago

Hi!

Same correction as above, using cap before the matrix command, would also be necessary further down in line 4115 of estout.ado: https://github.com/benjann/estout/blob/6bdff6f4e2416b177d69ebefc59aba0790f461cc/estout.ado#L4115

Thanks! Christian

Michael-E-Rose commented 5 years ago

I also had a equation / not found error when trying to use the indicator on a categorical variable in an ologit regression. Both changes above solved the issue.

Will the maintainer update the code?

benjann commented 5 years ago

Yes, I will. Sorry for the slow response. Give me some more time. There is a list of issues I have to take care of.

benjann commented 5 years ago

I had a look at this and it seems that Stata Corp fixed the problem in one of the Stata 15 updates. So no change to the code of estout.ado seems to be necessary. Using Revision 21 Mar 2019 of Stata 15.1, Emanuele's example works as expected on my computer:

. use http://www.stata-press.com/data/r15/towerlondon, clear
(Tower of London data)

. quietly melogit dtlm difficulty i.group || family: || subject: , or

. esttab, rename(difficulty "Test rename")

----------------------------
                      (1)   
                     dtlm   
----------------------------
dtlm                        
Test rename        -1.649***
                  (-8.53)   

1.group                 0   
                      (.)   

2.group            -0.249   
                  (-0.70)   

3.group            -1.052** 
                  (-2.63)   

_cons              -1.486***
                  (-5.22)   
----------------------------
/                           
var(_cons[~)        0.569   
                   (1.09)   

var(_cons[~)        1.138   
                   (1.66)   
----------------------------
N                     677   
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001

That is, the problem should go away once you update your copy of Stata 15. Type

. update all

to do so.