Repository: statsmodels/statsmodels

Issue:
summary.as_latex() output missing 1 row
#### Describe the bug

i compared the console output summary() and summary.as_latex(), found that the last row of result table gone missing.

#### Code Sample, a copy-pastable example if possible


```python
print(logit.summary().as_latex())
print(logit.summary())
```
<details>

**Note**: As you can see, there are many issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates.

**Note**: Please be sure you are using the latest released version of `statsmodels`, or a recent build of `main`. If your problem has been fixed in an unreleased version, you might be able to use `main` until a new release occurs. 

**Note**: If you are using a released version, have you verified that the bug exists in the main branch of this repository? It helps the limited resources if we know problems exist in the current main branch so that they do not need to check whether the code sample produces a bug in the next release.

[summary() output](https://github.com/BecksIsAlreadyTaken/Troubleshooting/blob/main/Screenshot%20from%202021-09-23%2023-31-14.png)

[summary().as_latex() output](https://github.com/BecksIsAlreadyTaken/Troubleshooting/blob/main/Screenshot%20from%202021-09-23%2023-31-35.png)

Here the row containing "Covariance Type:" and "LLR p-value" went missing.
</details>


If the issue has not been resolved, please file it in the issue tracker.

#### Expected Output

A full result table.

#### Output of ``import statsmodels.api as sm; sm.show_versions()``

<details>

[paste the output of ``import statsmodels.api as sm; sm.show_versions()`` here below this line]
INSTALLED VERSIONS
------------------
Python: 3.9.0.final.0
OS: Linux 5.4.0-86-generic #97-Ubuntu SMP Fri Sep 17 19:19:40 UTC 2021 x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

statsmodels
===========

Installed: 0.12.2 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/statsmodels)

Required Dependencies
=====================

cython: Not installed
numpy: 1.21.2 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/numpy)
scipy: 1.7.1 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/scipy)
pandas: 1.3.3 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/pandas)
    dateutil: 2.8.2 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/dateutil)
patsy: 0.5.1 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/patsy)

Optional Dependencies
=====================

matplotlib: 3.4.3 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/matplotlib)
    backend: TkAgg 
cvxopt: Not installed
joblib: 1.0.1 (/home/beck/anaconda3/envs/main/lib/python3.9/site-packages/joblib)

Developer Tools
================

IPython: Not installed
    jinja2: Not installed
sphinx: Not installed
    pygments: Not installed
pytest: Not installed
virtualenv: Not installed

</details>



Discussion:
~~I don't see it.~~
Both pictures show the same 6 parameter rows
last line of top table is missing.

It's better to post the text version than a screen shot.
[image](https://github.com/BecksIsAlreadyTaken/Troubleshooting/blob/main/Screenshot%20from%202021-09-24%2000-06-52.png)

missing the "Covariance Type:" and "LLR p-value"
\begin{center}
\begin{tabular}{lclc}
\toprule
\textbf{Dep. Variable:} &     DEFAULT      & \textbf{  No. Observations:  } &     9990    \\
\textbf{Model:}         &      Logit       & \textbf{  Df Residuals:      } &     9984    \\
\textbf{Method:}        &       MLE        & \textbf{  Df Model:          } &        5    \\
\textbf{Date:}          & Fri, 24 Sep 2021 & \textbf{  Pseudo R-squ.:     } &  0.04225    \\
\textbf{Time:}          &     00:06:07     & \textbf{  Log-Likelihood:    } &   -4068.5   \\
\textbf{converged:}     &       True       & \textbf{  LL-Null:           } &   -4247.9   \\
\bottomrule
\end{tabular}
\begin{tabular}{lcccccc}
                   & \textbf{coef} & \textbf{std err} & \textbf{z} & \textbf{P$> |$z$|$} & \textbf{[0.025} & \textbf{0.975]}  \\
\midrule
\textbf{HOUSE}     &       0.1795  &        0.066     &     2.729  &         0.006        &        0.051    &        0.308     \\
\textbf{CAR}       &      -0.6911  &        0.070     &    -9.815  &         0.000        &       -0.829    &       -0.553     \\
\textbf{HOUSE\_L}  &      -0.3912  &        0.085     &    -4.623  &         0.000        &       -0.557    &       -0.225     \\
\textbf{CAR\_L}    &       0.2089  &        0.124     &     1.684  &         0.092        &       -0.034    &        0.452     \\
\textbf{EDUCATION} &      -0.6296  &        0.029     &   -21.623  &         0.000        &       -0.687    &       -0.573     \\
\textbf{WORKTIME}  &      -0.0800  &        0.022     &    -3.607  &         0.000        &       -0.124    &       -0.037     \\
\bottomrule
\end{tabular}
%\caption{Logit Regression Results}
\end{center}
BUG,
I can replicate it using one of our unit test examples.

converting only the top table works correctly and includes the last line with `LLR p-value:`

```
summ = t.res1.summary()
print(summ.tables[0].as_latex_tabular())
```

Looks like there is a bug in merging the latex tables

same problem with Probit. and same problem in OLS
summary for latex has a del table[-1]
I guess this was supposed to remove a `======` line

```def summary_return(tables, return_fmt='text'):
    # join table parts then print
    if return_fmt == 'text':
       ....
    elif return_fmt == 'latex':
        # TODO: insert \hline after updating SimpleTable
        table = copy.deepcopy(tables[0])
        del table[-1]
        for part in tables[1:]:
            table.extend(part)
        return table.as_latex_tabular()
```
After a while of digging
a possible candidate is
https://github.com/statsmodels/statsmodels/pull/5814/files#diff-157f412d854ff1baeac4f504cb16fb5c7caf50c3f1762d6658c362cd4468d8ec

replaces "=" by ":" in defining dict, but replaced "=" also from content, dec_below.
reformatting doesn't give a useful diff 

But it looks like those mistakes are not in the fmt that are used
???

the `del table[-1]` is 10 years old from original code, so something else must have changed.

Problem is that `summary` has almost only smoke tests.

removing `del table[-1]` fixes the problem. But I have no guess how long this bug already occurred.

@BecksIsAlreadyTaken  Thanks a lot for reporting, problems in summary and plots are difficult to catch besides visual inspection.

I will have a PR later today, removing the del, and with unit tests for the number of lines in the latex return, that passes for the test_discrete cases.
I guess this is old,
There is a unit test for as_latex in regression/test_regression that compares the full latex summary text, added 9 years ago.
cov_type was added to summary 8 years ago, but that unit test never failed.

The unit test fails now after fixing this.

This might even have been wrong since the beginning, initial refactorings.
#1214 needed to add a line to the latex text in the unit test.

Resolving patch:
diff --git a/statsmodels/iolib/summary.py b/statsmodels/iolib/summary.py
--- a/statsmodels/iolib/summary.py
+++ b/statsmodels/iolib/summary.py
@@ -718,7 +718,6 @@ def summary_return(tables, return_fmt='text'):
     elif return_fmt == 'latex':
         # TODO: insert \hline after updating SimpleTable
         table = copy.deepcopy(tables[0])
-        del table[-1]
         for part in tables[1:]:
             table.extend(part)
         return table.as_latex_tabular()


Test patch:
diff --git a/statsmodels/discrete/tests/test_discrete.py b/statsmodels/discrete/tests/test_discrete.py
--- a/statsmodels/discrete/tests/test_discrete.py
+++ b/statsmodels/discrete/tests/test_discrete.py
@@ -142,6 +142,16 @@ def test_jac(self):
         score = self.res1.model.score(self.res1.params)
         assert_almost_equal(jacsum, score, DECIMAL_9) #Poisson has low precision ?
 
+    def test_summary_latex(self):
+        # see #7747, last line of top table was dropped
+        summ = self.res1.summary()
+        ltx = summ.as_latex()
+        n_lines = len(ltx.splitlines())
+        if not isinstance(self.res1.model, MNLogit):
+            # skip MNLogit which creates several params tables
+            assert n_lines == 19 + np.size(self.res1.params)
+        assert "Covariance Type:" in ltx
+
 
 class CheckBinaryResults(CheckModelResults):
     def test_pred_table(self):
diff --git a/statsmodels/regression/tests/test_regression.py b/statsmodels/regression/tests/test_regression.py
--- a/statsmodels/regression/tests/test_regression.py
+++ b/statsmodels/regression/tests/test_regression.py
@@ -994,6 +994,7 @@ def test_summary_as_latex():
 \\textbf{No. Observations:} &          16      & \\textbf{  AIC:               } &     233.2   \\\\
 \\textbf{Df Residuals:}     &           9      & \\textbf{  BIC:               } &     238.6   \\\\
 \\textbf{Df Model:}         &           6      & \\textbf{                     } &             \\\\
+\\textbf{Covariance Type:}  &    nonrobust     & \\textbf{                     } &             \\\\
 \\bottomrule
 \\end{tabular}
 \\begin{tabular}{lcccccc}