[Tex/LaTex] R Stargazer output unable to run in LaTex editor

rtables

TexMaker displays an error message when I run this code, stating that the first line "\begin{table}[!htbp]\centering" is causing issues. Any insight is appreciated.

\begin{table}[!htbp] \centering 
\caption{Descriptive Statistics - Bangladesh 1991} 
\label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} &
\multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1
{c}{Max} \\ 
\hline \\[-1.8ex] 
Consumption & 826 & 4,163.1 & 2,167.9 & 1,352.5 & 27,447.7 \\ 
Age (Years) & 826 & 40.8 & 12.0 & 18 & 75 \\ 
Education (Years) & 826 & 1.0 & 0.2 & 0 & 1 \\ 
Sex & 826 & 2.4 & 3.3 & 0 & 16 \\ 
Household Land (Decimals) & 826 & 81.0 & 246.8 & 0.2 & 4,618.0 \\ 
\hline \\[-1.8ex] 
\multicolumn{6}{l}{Figures reference a 1991 study on 826 households in
Bangladesh.} \\ 
\multicolumn{6}{l}{Full data set includes 24 variables on information at
the} \\ 
\multicolumn{6}{l}{household (head's education, land ownership,
expenditure, etc.)} \\ 
\multicolumn{6}{l}{and village (infastructure, price information of the
main consumer} \\ 
\multicolumn{6}{l}{goods, etc.) levels.} \\ 
\end{tabular} 
\end{table} 

Best Answer

Welcome to TeX.SX. As @Torbjørn indicated, the error is due to a missing brace.

Your table presents a few challenges with respect to sizing and alignment. People have difference preferences and ways of achieving their desired solution.

The following might help you achieve your final desired outcome.There are comments throughout the example to explain what the code does. You might also read "Tables in LATEX2ε: Packages and Methods".

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs} % for toprule, midrule and bottomrule
\usepackage{siunitx} % for alignment of numbers in columns
\usepackage{adjustbox}
\sisetup{
    group-minimum-digits = {3}, % use this so that the comma is placed when number are thousands
    group-separator = {,} % the thousands separator is a comma
    }

    \begin{document}
        \begin{table}[htb] \centering 
            \caption{Descriptive Statistics - Bangladesh 1991} 
            \label{} 
            \begin{adjustbox}{width=\linewidth} %this sets the table within the line with of the page
            \begin{tabular}{
                    @{\extracolsep{15pt}} % extra spacing between columns. adjust according to preference.
                    l % first column is left aligned
                    S[table-format=3.0] %second column, 3 integers, no decimals
                    *3{S[table-format=4.1]} %3rd, 4th & 5th columns, 4 integers, 1 decimal
                    S[table-format=5.1] % 6th column, 5 integers, 1 decimal
                    @{}
                } 
                \toprule
                Statistic & {N} & {Mean} & {St. Dev.} & {Min} & {Max} \\ % protect the headings in braces to avoid siunitx typesetting them
                \midrule 
                Consumption & 826 & 4163.1 & 2167.9 & 1352.5 & 27447.7 \\ 
                Age (Years) & 826 & 40.8 & 12.0 & 18 & 75 \\ 
                Education (Years) & 826 & 1.0 & 0.2 & 0 & 1 \\ 
                Sex & 826 & 2.4 & 3.3 & 0 & 16 \\ 
                Household Land (Decimals) & 826 & 81.0 & 246.8 & 0.2 & 4618.0 \\ 
               \bottomrule
             \end{tabular}
           \end{adjustbox} % end of adjustbox
        \end{table}
    \noindent Figures reference a 1991 study on 826 households in Bangladesh. Full data set includes 24 variables on information at household (head's education, land ownership, expenditure, etc.) and village (infrastructure, price information of the main consumer goods, etc.) levels. 

    \end{document}

enter image description here