Table column error

After clean up your document preamble (see comments below your question) and remove all packages and new commands definitions, which are not needed in your table, I obtain the following result:

enter image description here

As you can see, some long column headers I wrote in two lines and use abbreviation for names. By this the column becomes narrowed and can fit in \textwidth using \footnotesize font sioze:

\documentclass[a4paper, 12pt]{article}
\usepackage[showframe,
            margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{booktabs, makecell,  tabularx}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
\caption{Descriptive Statistics for Banks’ financial data and macro variables}
\label{tab1}
    \centering
    \footnotesize
\begin{tabularx}{\linewidth}{@{} l X cc S[table-format=2.3] cc @{}}
    \toprule
\texttt{Variables}
    & \makecell[b]{Description}
    & \makecell[b]{No of\\ observ.}
    & \makecell[b]{Mean}
    & {\makecell[b]{Standard\\ Deviation}}
    & \makecell[b]{Max}
    & \makecell[b]{Min}   \\
    \midrule
%\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-5} \cmidrule(lr)
%{6-6} \cmidrule(lr){7-7}
Specialization  & total loans-to-total assets ratio   & 8743  & 0.164 &  7.144 & 0.659 & 0.046  \\
Credit quality  & Loans loss provision-to-total loans & 8950  & 0.152 &  5.102 & 0.338 & 1.766  \\
Diversification & Non-interest income-to-total income & 8945  & 0.245 & 10.172 & 0.509 & 0.396  \\
Profitability   & Return on assets (ROA)              & 8746  & 0.146 &  4.514 & 0.132 & 0.115  \\
Real GDP growth & Quarter-over-Quarter growth         & 8456  & 0.045 &  0.612 & 1.192 & 0.010  \\
Log (Inflation) & Quarter-over-Quarter growth         & 8752  & 0.123 &  3.890 & 0.134 & 0.118  \\
Log (unemployment rate) 
                & Quarter-over-Quarter growth         & 8563  & 0.315 & 13.072 & 0.508 & 0.396  \\
Exchange rate   & Quarter-over-Quarter growth         & 8745  & 0.278 & 11.156 & 0.543 & 0.016  \\
    \bottomrule
\end{tabularx}
    \end{table}
\end{document}

Some comments and observations:

  • You load the geometry package twice.
  • You load inputenc twice, with incompatible options
  • You define \mc twice. For the second (re)definition, you must use \renewcommand, not \newcommand.
  • You define the tabular environment to have 6 columns overall, but the data show you actually have 7 columns.
  • You define some custom column types but don't seem to be using all that much.

Anyway, as long as you're willing to abbreviate some of the header cells stings, you can make do with the basic l and c column types.

enter image description here

  \documentclass[a4paper, 12pt]{article} 
  %% (reduced the preamble to its bare minimum)
  \usepackage[margin=2cm]{geometry}
  \usepackage[utf8]{inputenc}
  \usepackage[T1]{fontenc}
  \usepackage{booktabs}
  \usepackage{lmodern,eucal}
  \usepackage[english]{babel}
  \usepackage[onehalfspacing]{setspace} 
  \usepackage{siunitx}  

  \begin{document}

  \begin{table}[h!]
  \caption{Descriptive statistics for banks' financial
           data and macro variables\strut}
  \label{tab1}
  \setlength\tabcolsep{0pt} % make LaTex determine inter-col. whitespace
  \small
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
     ll cc S[table-format=2.3] cc @{}}
  \toprule 
  Variables & Description & No of obs & Mean
  & {Std Dev} & Max & Min \\
  \midrule
 Specialization  & total loans-to-total assets ratio  & 8743 & 0.164 & 7.144 & 0659    & 0.046\\ 
 Credit quality  & Loans loss provision-to-total loans&8950  & 0.152 & 5.102 &0.338    & 1.766\\ 
 Diversification & Non-interest income-to-total income&8945  & 0.245 &10.172 &0.509    & 0.396\\
 Profitability   &Return on assets (ROA)              &8746  & 0.146 & 4.514 &0.132    & 0.115\\ 
 \addlinespace
 Real GDP growth & q-o-q growth        &8456  & 0.045 & 0.612 &1.192    & 0.010\\
 Log (Inflation) &q-o-q growth         &8752  & 0.123 & 3.890 &0.134    & 0.118\\
 Log (unempl.\ rate) &q-o-q growth     &8563  & 0.315 &13.072 &0.508    & 0.396\\
 Exchange rate   &q-o-q growth         &8745  & 0.278 &11.156 &0.543    & 0.016\\
  \bottomrule 
  \end{tabular*}
  \end{table}
  \end{document}

Tags:

Tables