TransWikia.com

Write notes under tables generated with stargazer

TeX - LaTeX Asked on May 10, 2021

I created these descriptive statistics table using the “stargazer" package, in RStudio and I would like to write a note under this table, but I am not able to. The only thing I could do was a note, that could not be justified.

documentclass{beamer}
usetheme{Madrid}
usepackage{breqn}
usepackage[super]{nth}
usepackage{amsmath}
usepackage{breqn}

beamerdefaultoverlayspecification{<+->}

usepackage[utf8]{inputenc}
usepackage{ragged2e}
usepackage{etoolbox}
usepackage{lipsum}

begin{document}
maketitle

begin{frame}{Expected results}
% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Oct 21, 2020 - 15:39:55
begin{table}[!htbp] centering 
  caption{Descriptive statistics} 
  label{} 
resizebox{textwidth}{!} {%
begin{tabular}{@{extracolsep{5pt}}lccccc} 
[-1.8ex]hline 
hline [-1.8ex] 
Variable & multicolumn{1}{c}{N} & multicolumn{1}{c}{Mean} & multicolumn{1}{c}{St. Dev.} & multicolumn{1}{c}{Min} & multicolumn{1}{c}{Max}  
hline [-1.8ex] 
Child deaths caused by infectious diseases & 28,119 & 0.486 & 2.487 & 0 & 230  
Access to piped water and sewage (%) & 28,119 & 57.197 & 29.119 & 0.000 & 99.474  
Illiteracy rate (%) & 28,119 & 30.453 & 15.129 & 2.022 & 70.261  
Years of schooling (population above 25) & 28,119 & 3.780 & 1.217 & 0.814 & 8.577  
Gini index & 28,119 & 0.582 & 0.092 & 0.364 & 0.880  
Population & 28,119 & 23,850.370 & 116,238.000 & 958 & 10,434,252  Income per capita (R$)  & 28,119 & 148.598 & 84.234 & 34.527 & 762.052  
hline [-1.8ex] 
end{tabular}%
}


end{table} 
end{frame}

2 Answers

Instead of resizebox I suggest using tabularx in combination with a smaller font size and a reduced tabcolsep. In the following example, I also replaced the horizontal lines by lines from the booktabs package and added a small vertical white space ebtween adjacent rows as a guide to the eye. For the table note, I used a multicolumn:

enter image description here

documentclass{beamer}
usetheme{Madrid}

usepackage{booktabs}
usepackage{tabularx}

begin{document}


begin{frame}{Expected results}

begin{table}[!htbp] 
centering 
footnotesize
setlength{tabcolsep}{4pt}
setlength{defaultaddspace}{0.9pt}
caption{Descriptive statistics} 
begin{tabularx}{textwidth}{@{}>{raggedrightarraybackslash}Xccccc@{}} 
toprule 
Variable & N & Mean & St. Dev. & Min & Max  
midrule
Child deaths caused by infectious diseases & 28,119 & 0.486      & 2.487       & 0      & 230         addlinespace
Access to piped water and sewage (%)      & 28,119 & 57.197     & 29.119      & 0.000  & 99.474      addlinespace
Illiteracy rate (%)                       & 28,119 & 30.453     & 15.129      & 2.022  & 70.261      addlinespace
Years of schooling (population above 25)   & 28,119 & 3.780      & 1.217       & 0.814  & 8.577       addlinespace
Gini index                                 & 28,119 & 0.582      & 0.092       & 0.364  & 0.880       addlinespace
Population                                 & 28,119 & 23,850.370 & 116,238.000 & 958    & 10,434,252  addlinespace
Income per capita (R$)                    & 28,119 & 148.598    & 84.234      & 34.527 & 762.052     
bottomrule
multicolumn{6}{@{}p{textwidth}@{}}{The table shows the descriptive statistics of the data used in the paper. Child deaths caused by infectious diseases were obtained in the dataset. Access to piped water, illiteracy rate, years of schooling of the population above 25, Gini index, population, and income per capita were all obtained in the Ipeadata that uses the data provided by the 2000 census.}
end{tabularx}
end{table} 
end{frame}
end{document}

Since all entries in the "N" column are basically identical, couls you remove that column entirely and add this information into the caption of your table? The result could look something like the following:

enter image description here

documentclass{beamer}
usetheme{Madrid}

usepackage{booktabs}
usepackage{tabularx}

begin{document}


begin{frame}{Expected results}

begin{table}[!htbp] 
centering 
footnotesize
setlength{tabcolsep}{4pt}
setlength{defaultaddspace}{2.75pt}
caption{Descriptive statistics; N = 28,119} 
begin{tabularx}{textwidth}{@{}>{raggedrightarraybackslash}Xcccc@{}} 
toprule 
Variable                                   & Mean       & St. Dev.    & Min    & Max  
midrule
Child deaths caused by infectious diseases & 0.486      & 2.487       & 0      & 230         addlinespace
Access to piped water and sewage (%)      & 57.197     & 29.119      & 0.000  & 99.474      addlinespace
Illiteracy rate (%)                       & 30.453     & 15.129      & 2.022  & 70.261      addlinespace
Years of schooling (population above 25)   & 3.780      & 1.217       & 0.814  & 8.577       addlinespace
Gini index                                 & 0.582      & 0.092       & 0.364  & 0.880       addlinespace
Population                                 & 23,850.370 & 116,238.000 & 958    & 10,434,252  addlinespace
Income per capita (R$)                    & 148.598    & 84.234      & 34.527 & 762.052     
bottomrule
multicolumn{5}{@{}p{textwidth}@{}}{The table shows the descriptive statistics of the data used in the paper. Child deaths caused by infectious diseases were obtained in the dataset. Access to piped water, illiteracy rate, years of schooling of the population above 25, Gini index, population, and income per capita were all obtained in the Ipeadata that uses the data provided by the 2000 census.}
end{tabularx}
end{table} 
end{frame}
end{document}

Correct answer by leandriis on May 10, 2021

I suspect that you looking for something like this:

enter image description here

With use of the threeparttable, cellspace and siunitx package:

documentclass{beamer}
usetheme{Madrid}
beamerdefaultoverlayspecification{<+->}
usepackage{ragged2e}
usepackage{array, booktabs, threeparttable}
usepackage[column=O]{cellspace}
usepackage{siunitx}

begin{document}

begin{frame}{Expected results}
    begin{table}
    footnotesizelinespread{0.84}selectfont
    setlengthcellspacetoplimit{3pt}
    setlengthcellspacebottomlimit{3pt}
    setlengthtabcolsep{0pt}
begin{threeparttable}
caption{Descriptive statistics}
begin{tabular*}{linewidth}{@{extracolsep{fill}}
                             O{m{0.33linewidth}} 
                             S[table-format=5.0]
                        *{2}{S[table-format=2.3]}
                             S[table-format=1.3]
                             S[table-format=2.3]}
    toprule
Variable & {N} & {Mean} & {St. Dev.} & {Min} & {Max} 
    midrule
Child deaths caused by infectious diseases 
    & 28 119 & 0.486 & 2.487 & 0 & 230 
Access to piped water and sewage (%) 
    & 28 119 & 57.197 & 29.119 & 0.000 & 99.474 
Illiteracy rate (%) 
    & 28 119 & 30.453 & 15.129 & 2.022 & 70.261 
Years of schooling (population above 25) 
    & 28 119 & 3.780 & 1.217 & 0.814 & 8.577 
Gini index 
    & 28 119 & 0.582 & 0.092 & 0.364 & 0.880 
Population 
    & {28 119} & {23 850 370} & {116 238 000} & {958}    & {10 434 252}  
Income per capita (R$)  
    & {28 119} & {148 598}    & {84 234}      & {34 527} & {762 052} 
    midrule[heavyrulewidth]
end{tabular*}scriptsize
    begin{tablenotes}[para, flushleft]
    item[*]    (p<0.1)
    item[**]   (p<0.01)
    item[***]  (p<0.001)
    end{tablenotes}
end{threeparttable}
    end{table}
end{frame}
end{document}

Addendum: With desired text below the table, instead threeparttable is used ˙[referable]{threeparttablex}`, text in the first column is in one line

enter image description here

documentclass{beamer}
usetheme{Madrid}
beamerdefaultoverlayspecification{<+->}
usepackage{ragged2e}
usepackage{array, booktabs}
usepackage[referable]{threeparttablex}
usepackage[column=O]{cellspace}
usepackage{siunitx}

begin{document}

begin{frame}{Expected results}
    begin{table}
    footnotesize
    setlengthcellspacetoplimit{2pt}
    setlengthcellspacebottomlimit{2pt}
    setlengthtabcolsep{0pt}
begin{threeparttable}
caption{Descriptive statistics for $N=num{28 112}$}
begin{tabular*}{linewidth}{@{extracolsep{fill}}
                             Ol
                        *{2}{S[table-format=2.3]}
                             S[table-format=1.3]
                             S[table-format=2.3]}
    toprule
Variable    & {Mean} & {St. Dev.} & {Min} & {Max} 
    midrule
Child deaths caused by infectious diseases
            &  0.486 &  2.487     & 0     & 230     
Access to piped water and sewage (%)
            & 57.197 & 29.119     & 0.000 & 99.474  
Illiteracy rate (%)
            & 30.453 & 15.129     & 2.022 & 70.261  
Years of schooling (population above 25)
            & 3.780  & 1.217      & 0.814 & 8.577   
Gini index
            & 0.582  & 0.092      & 0.364 & 0.880   
    addlinespace
Population
            & {23 850 370} & {116 238 000} & {958}    & {10 434 252} 
Income per capita (R$)
            & {148 598}    & {84 234}      & {34 527} & {762 052} 
    midrule[heavyrulewidth]
end{tabular*}scriptsize
    begin{tablenotes}[flushleft]
note{
the table shows the descriptive statistics of the data used in the paper. Child deaths caused by infectious diseases were obtained in the dataset. Access to piped water, illiteracy rate, years of schooling of the population above 25, Gini index, population, and income per capita were all obtained in the Ipeadata that uses the data provided by the 2000 census.
    }    
    end{tablenotes}
end{threeparttable}
    end{table}
end{frame}
end{document}

Answered by Zarko on May 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP