Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Asking about using -tabout- program and LaTeX for making publication tables

    Dear all,

    I have tried to use the Stata program -tabout- which is published by Ian Watson, I have run the suggesting codes of Ian Watson from the tutorial ( You can see this by downloading the attached file or search it via Google by typing "Publication quality tables in Stata:
    a tutorial for the tabout program".
    Code:
    /*tex
    tex \usepackage{booktabs}
    tex \usepackage{tabularx}
    tex*/
    
    texdoc init top, replace
    /*tex
    tex \begin{center}
    tex \footnotesize
    tex \newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
    tex \begin{tabularx} {#} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
    tex \toprule
    tex*/
    
    texdoc init bot, replace
    /*tex
    tex \bottomrule
    tex \addlinespace[.75ex]
    tex \end{tabularx}
    tex \par
    tex \scriptsize{\emph{Source: }#}
    tex \normalsize
    tex \end{center}
    tex*/
    
    
    sysuse cancer, clear
    la var died "Patient died"
    la def ny 0 "No" 1 "Yes", modify
    la val died ny
    recode studytime (min/10 = 1 "10 or less months") ///
    (11/20 = 2 "11 to 20 months") ///
    (21/30 = 3 "21 to 30 months") ///
    (31/max = 4 "31 or more months") ///
    , gen(stime)
    la var stime "To died or exp. end"
    tabout stime died using table1.tex, ///
    cells(freq col cum) format(0 1) clab(No. Col_% Cum_%) ///
    replace ///
    style(tex) bt cl1(2-10) cl2(2-4 5-7 8-10) font(bold) ///
    topf(top.tex) botf(bot.tex) topstr(14cm) botstr(cancer.dta)
    
    
    sysuse nlsw88, clear
    la var south "Location"
    la def south 0 "Does not live in the South" ///
    1 "Lives in the South"
    la val south south
    la var race "Race"
    la def race 1 "White" 2 "Black" 3 "Other"
    la val race race
    
    la var collgrad "Education"
    la def collgrad 0 "Not college graduate" 1 "College graduate"
    la val collgrad collgrad
    gen wt = 10 * runiform()
    tabout south race collgrad [iw=wt] using table3.tex, ///
    cells(freq row col) format(0c 1p 1p) layout(cb) h1(nil) h3(nil) npos(row) ///
    replace ///
    style(tex) bt font(bold) rotate(60) ///
    topf(top.tex) botf(bot.tex) topstr(15cm) botstr(nlsw88.dta)
    Then, copying and pasting the resutls to LaTex. Unfortunately, it does not work. How to fix it in order to get the 'standard' table. In the case, it is the Table #1 of the tutorial on page #13.

    Code:
    \begin{table}
    
    & \multicolumn{9}{c}{\textbf{Patient died}} \\
    
    \cmidrule(l{.75em}){2-10}
    
    \textbf{To died or exp. end} & \multicolumn{3}{c}{\textbf{No}} & \multicolumn{3}{c}{\textbf{Yes}} & \multicolumn{3}{c}{\textbf{Total}} \\
    
    \cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-7}\cmidrule(l{.75em}){8-10}
    
    &No.&Col \%&Cum \%&No.&Col \%&Cum \%&No.&Col \%&Cum \% \\
    
    \midrule
    
    10 or less months&4&23.5&23.5&15&48.4&48.4&19&39.6&39.6 \\
    
    11 to 20 months&6&35.3&58.8&8&25.8&74.2&14&29.2&68.8 \\
    
    21 to 30 months&2&11.8&70.6&7&22.6&96.8&9&18.8&87.5 \\
    
    31 or more months&5&29.4&100.0&1&3.2&100.0&6&12.5&100.0 \\
    
    \textbf{Total}&17&100.0&&31&100.0&&48&100.0& \\
    
    
    
    
    \end{table}
    It is my first time using LaTex and -tabout-. Thank you all in advance!

  • #2
    Your latex document does not compile because you have not declared a documentclass. Also \cmidrule requires the booktabs package and the actual table needs to be set in the tabular environment:

    Code:
    \documentclass[]{scrartcl}
    
    \usepackage{booktabs}
    \begin{document}
    
    \begin{table}
    \begin{tabular}{llllllllll}
    
    & \multicolumn{9}{c}{\textbf{Patient died}} \\
    
    \cmidrule(l{.75em}){2-10}
    
    \textbf{To died or exp. end} & \multicolumn{3}{c}{\textbf{No}} & \multicolumn{3}{c}{\textbf{Yes}} & \multicolumn{3}{c}{\textbf{Total}} \\
    
    \cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-7}\cmidrule(l{.75em}){8-10}
    
    &No.&Col \%&Cum \%&No.&Col \%&Cum \%&No.&Col \%&Cum \% \\
    
    \midrule
    
    10 or less months&4&23.5&23.5&15&48.4&48.4&19&39.6&39.6 \\
    
    11 to 20 months&6&35.3&58.8&8&25.8&74.2&14&29.2&68.8 \\
    
    21 to 30 months&2&11.8&70.6&7&22.6&96.8&9&18.8&87.5 \\
    
    31 or more months&5&29.4&100.0&1&3.2&100.0&6&12.5&100.0 \\
    
    \textbf{Total}&17&100.0&&31&100.0&&48&100.0& \\
    \end{tabular}
    
    \end{table}
    \end{document}


    Comment


    • #3
      Thank you very much for your help, Roberto!
      I have also downloaded the following book (a draft version) "Applied LATEX for Economists,
      Social Scientists and Others from Trinity College Dublin" for learning more.

      Comment


      • #4
        Glad, it helped. Here are two other resources I found really helpful while using LaTeX:

        Comment


        • #5
          Dear Roberto,

          I have a question for you. How to convert directly LaTeX pdf file to Microsoft word file? I have searched on the Internet, however, I have not found something can help me, several suggestion and it makes me confused.
          Thank you in advance!

          Comment


          • #6
            Thong Nguyen I think you found nothing on the internet because the interest in doing such things is limited You either write in LaTeX or Word -- not both. If you want to use Word why not using tabout to produce a table that you can copy into Word and format it there?

            Comment


            • #7
              Dear Roberto,

              Because, when I used -tabout- for making tables directly to Word, its format is so bad; additionally, I would like to have just tables, then copying and pasting them into Word, and start to write my report. Of course, I can use Adobe Acrobat Pro XI for converting .pdf file to .doc file. The problem I got is why I always have fontsizes as 10pt, not 13pt? Could you help me to fix it, please?

              Code:
              % !TEX TS-program = xelatex
              
              \documentclass[a4paper,13pt]{extarticle}
              
              \usepackage{extsizes}
              \usepackage{booktabs}
              \usepackage{color}
              \usepackage[utf8]{inputenc}
              \usepackage[vietnamese]{babel}
              \usepackage{times}
              \usepackage{longtable}
              \usepackage{colortbl}
              \usepackage{fontspec}
              \usepackage{xunicode}
              \usepackage{xltxtra}
              \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
              
              \setmainfont{Times New Roman}
              \fontsize{13pt}{18pt}\selectfont
              \begin{document}
                  \begin{table}
              Thank you very much, Roberto!

              Comment


              • #8
                So when you use Adobe Acrobat it converts to a wrong fontsize? I am afraid, I cannot help you with that. I would rather write the whole document in LaTeX. But when you insist using word you should try to avoid to go the long way over LaTeX, try the style(tab) option of tabout, copy the table to Excel and copy it to Word from there (just one idea).

                Comment


                • #9
                  Thank you for your reply, Roberto.

                  Comment


                  • #10
                    Originally posted by Thong Nguyen View Post

                    Then, copying and pasting the resutls to LaTex. Unfortunately, it does not work. How to fix it in order to get the 'standard' table. In the case, it is the Table #1 of the tutorial on page #13.

                    Code:
                    \begin{table}
                    
                    & \multicolumn{9}{c}{\textbf{Patient died}} \\
                    
                    \cmidrule(l{.75em}){2-10}
                    
                    \textbf{To died or exp. end} & \multicolumn{3}{c}{\textbf{No}} & \multicolumn{3}{c}{\textbf{Yes}} & \multicolumn{3}{c}{\textbf{Total}} \\
                    
                    \cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-7}\cmidrule(l{.75em}){8-10}
                    
                    &No.&Col \%&Cum \%&No.&Col \%&Cum \%&No.&Col \%&Cum \% \\
                    
                    \midrule
                    
                    10 or less months&4&23.5&23.5&15&48.4&48.4&19&39.6&39.6 \\
                    
                    11 to 20 months&6&35.3&58.8&8&25.8&74.2&14&29.2&68.8 \\
                    
                    21 to 30 months&2&11.8&70.6&7&22.6&96.8&9&18.8&87.5 \\
                    
                    31 or more months&5&29.4&100.0&1&3.2&100.0&6&12.5&100.0 \\
                    
                    \textbf{Total}&17&100.0&&31&100.0&&48&100.0& \\
                    
                    
                    
                    
                    \end{table}
                    It is my first time using LaTex and -tabout-. Thank you all in advance!
                    Hello Thong,

                    I am also trying out the tabout tutorial file: but I couldn't get the code diagram (as quoted) you posted in your first post? Stata gives me an error-prone tex file as below:

                    Code:
                    \documentclass[]{scrartcl}
                    
                    
                    
                    
                    \usepackage{booktabs}
                    
                    \begin{document}
                    
                    
                    
                    
                    \begin{center}
                    
                    \footnotesize
                    
                    \newcolumntype{Y}{>{\raggedleft\arraybackslash}X}
                    
                    \begin{tabularx} {14cm} {@{} l Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y@{}} \\
                    
                    \toprule
                    
                    & \multicolumn{9}{c}{\textbf{Patient died}} \\
                    
                    \cmidrule(l{.75em}){2-10}
                    
                    \textbf{To died or exp. end} & \multicolumn{3}{c}{\textbf{No}} & \multicolumn{3}{c}{\textbf{Yes}} & \multicolumn{3}{c}{\textbf{Total}} \\
                    
                    \cmidrule(l{.75em}){2-4} \cmidrule(l{.75em}){5-7}\cmidrule(l{.75em}){8-10}
                    
                    &No.&Col \%&Cum \%&No.&Col \%&Cum \%&No.&Col \%&Cum \% \\
                    
                    \midrule
                    
                    10 or less months&4&23.5&23.5&15&48.4&48.4&19&39.6&39.6 \\
                    
                    11 to 20 months&6&35.3&58.8&8&25.8&74.2&14&29.2&68.8 \\
                    
                    21 to 30 months&2&11.8&70.6&7&22.6&96.8&9&18.8&87.5 \\
                    
                    31 or more months&5&29.4&100.0&1&3.2&100.0&6&12.5&100.0 \\
                    
                    \textbf{Total}&17&100.0&&31&100.0&&48&100.0& \\
                    
                    \bottomrule
                    
                    \addlinespace[.75ex]
                    
                    \end{tabularx}
                    
                    \par
                    
                    \scriptsize{\emph{Source: }cancer.dta}
                    
                    \normalsize
                    
                    \end{center}
                    
                    
                    
                    
                    \end{document}

                    Comment

                    Working...
                    X