TiesdeKok / ipystata

Enables the use of Stata together with Python via Jupyter (IPython) notebooks.
192 stars 68 forks source link

margins command not displayed entirely #19

Closed randomgambit closed 8 years ago

randomgambit commented 8 years ago

Hi Tiesdekok,

I hope you dont mind all these messages ;-)

Here is another bug. The output from the margins command is not displayed in the notebook.

%%stata
sysuse auto, clear
reg price mpg headroom length

gives

(1978 Automobile Data)

      Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  3,    70) =    7.59
       Model |   155836477     3  51945492.2           Prob > F      =  0.0002
    Residual |   479228920    70  6846127.42           R-squared     =  0.2454
-------------+------------------------------           Adj R-squared =  0.2130
       Total |   635065396    73  8699525.97           Root MSE      =  2616.5

------------------------------------------------------------------------------
       price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         mpg |  -174.3133    87.4079    -1.99   0.050    -348.6428    .0162904
    headroom |  -520.2934   422.6865    -1.23   0.222    -1363.315    322.7283
      length |   31.36592   24.14222     1.30   0.198    -16.78422    79.51607
       _cons |   5540.349   5872.757     0.94   0.349    -6172.495    17253.19

but

%%stata
margins, at (mpg=(10 20 30))

gives

Predictive margins                                Number of obs   =         74
Model VCE    
Expression   
1._at        
2._at        
3._at        
------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         _at |
          1  |   8134.526   1033.256     7.87   0.000     6073.761    10195.29
          2  |   6391.393   324.6128    19.69   0.000     5743.973    7038.813
          3  |    4648.26   819.2416     5.67   0.000     3014.334    6282.186

as you can see we are missing the means after the at.

Correct output from stata is

. margins, at (mpg=(10 20 30))

Predictive margins                                Number of obs   =         74
Model VCE    : OLS

Expression   : Linear prediction, predict()

1._at        : mpg             =          10

2._at        : mpg             =          20

3._at        : mpg             =          30

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         _at |
          1  |   8134.526   1033.256     7.87   0.000     6073.761    10195.29
          2  |   6391.393   324.6128    19.69   0.000     5743.973    7038.813
          3  |    4648.26   819.2416     5.67   0.000     3014.334    6282.186
------------------------------------------------------------------------------
TiesdeKok commented 8 years ago

Thanks for the bug-report. My code that processed the log-file into the final output that is printed in the Notebook is a little bit wonky, I will look into it and modify it to also properly display output from the Margins command.