Announcement

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

  • -summtab- available on SSC: program to generate summary tables (table 1)

    Thanks to Kit Baum as always, the program summtab is now available on SSC.

    summtab facilitates the creation of publication-quality summary tables in Word or Excel format. The types of summary tables produced are often "Table 1" in publications.

    From the abstract on SSC:


    Manually typing summary tables from statistical output is tedious, time-consuming, and error-prone. Therefore, it is never recommended to enter tables “by hand.” The summtab command facilitates and automates the creation of a publication-quality summary table (usually “Table 1” in research articles) output to Word using the Stata command putdocx, thus saving the user time and eliminating copy-and-paste errors. The summtab command summarizes both continuous and categorical variables, overall and/or across levels of (i.e., stratified by) a categorical variable. Various options allow the user to select which summary statistics to report, how to format numbers, and whether to output as both a Word and Excel file, among other options.

    See the help file for examples and features, or try it out now using:

    Code:
    ssc install summtab
    sysuse auto, clear
    summtab, by(foreign) cont_vars(price mpg weight length) cat_vars(rep78) mean median pval landscape replace wordname(summary_table) title(My Table 1)
    summtab requires Stata 15, as it uses putdocx.

    Please feel free to email me (see help file) if you find any bugs or notice any features left out that you'd like added, or simply to let me know if you're finding the package useful.

    Special thanks to members of the Duke Global Health Institute Research Design & Analysis Core for testing the code and providing recommendations for improving the program.


    Full disclosure, I used the code provided by William Parker here as the beginning structure for my code, but made many additions and changes including new formatting and more control over formatting, the option to output to Excel, more statistics (medians, min, max, etc.), the ability to suppress p-values, etc.
    Attached Files

  • #2
    Hi John,
    Was testing the codes and receiving error message in Stata 15.1, Mac OS: 10.13.4, Sierra High. Code's below:


    Code:
     ssc install summtab
    checking summtab consistency and verifying not already installed...
    installing into /Users/Rom/Library/Application Support/Stata/ado/plus/...
    installation complete.
    
    .
    end of do-file
    
    . do "/var/folders/hs/28h0__092_1b33vgvp_sg2lr0000gn/T//SD00910.000000"
    
    summtab, by(foreign) cont_vars(price mpg weight length) ///
     cat_vars(rep78) mean median pval landscape replace ///
     wordname(summary_table) title(My Table 1)
    Please install package distinct from SSC in order to run this program;
    you can do so by clicking this link: auto-install distinct
    r(499);
    
    end of do-file
    
    r(499);
    
    //INSTALLING distinct:
    
    ssc install distinct
    
    checking distinct consistency and verifying not already installed...
    installing into /Users/Rom/Library/Application Support/Stata/ado/plus/...
    installation complete.
    
    . do "/var/folders/hs/28h0__092_1b33vgvp_sg2lr0000gn/T//SD00910.000000"
    
    . summtab, by(foreign) cont_vars(price mpg weight length) ///
    > cat_vars(rep78) mean median pval landscape replace ///
    > wordname(summary_table) title(My Table 1)
    r(198);

    Roman

    Comment


    • #3
      On distinct:

      There is an older version on SSC, which is enough for John's purpose. .

      Later versions can be traced on the Stata Journal website:

      SJ-15-3 dm0042_2 . . . . . . . . . . . . . . . . Software update for distinct
      (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
      Q3/15 SJ 15(3):899
      improved table format and display of large numbers of
      observations

      SJ-12-2 dm0042_1 . . . . . . . . . . . . . . . . Software update for distinct
      (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
      Q2/12 SJ 12(2):352
      options added to restrict output to variables with a minimum
      or maximum of distinct values

      SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct observations
      (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
      Q4/08 SJ 8(4):557--568
      shows how to answer questions about distinct observations
      from first principles; provides a convenience command


      I like distinct but hints in the 2008 paper above would let John free his program of dependence on it.

      Comment


      • #4
        I tried to execute your sample code Stata 15.1 and IO received error 198 (after I had installed -distinct-)

        Comment


        • #5
          Thanks everyone for testing the code! Would one of you mind running the command
          Code:
          set trace on
          and then running the program and let me know what line in the code gives the error?

          By the way, Alexander, are you on a Mac as well? I don't think anyone who tested the program before this tested it on a Mac.

          Nick, thanks for the tip on potentially freeing my program of dependence on distinct. I'm going to look into doing this, as I like to keep my programs free of as many user-written program dependencies as possible.
          Last edited by John Gallis; 24 Apr 2018, 07:23.

          Comment


          • #6
            Unless there are an extraordinary number of distinct values, this device is practical:

            Code:
            . sysuse auto
            (1978 Automobile Data)
            
            . qui tab rep78
            
            . di r(r)
            5
            levelsof now also emits r(r) with the same meaning.

            Comment


            • #7
              My previous codes belong to my machine at home, but running the same command in my work place computer (Mac OS Sierra: 10.12.6) did not flag any issue. The MS Office versions are also different, the one at home is more recent version (office 365 subscription) than here (MS Office for MAC: version: 16.11.1). Unfortunately I can't test the program with -trace on- in my machine now as I am at work.
              Roman

              Comment


              • #8
                Windows 10. Stata 15.1
                Trace on.


                Code:
                summtab, cont_vars(kp9_921a) pval mean
                  -------------------------------------------------------------------------- begin summtab ---
                  - version 15
                  - syntax [if] [in], [by(varname) cont_vars(varlist) cat_vars(varlist) mean median range pmis
                > s total pval incmiss cont_ptype(integer 1) cat_ptype(integer 1) mnfmt(integer 2) medfmt(inte
                > ger 1) rangefmt(integer 1) pfmt(integer 3) title(string) wordname(string) excel excelname(st
                > ring) replace wts(varname) *]
                no variables defined
                (error in option cont_vars())

                Comment


                • #9
                  Hi Alexander,

                  Since I don't know which dataset you are using, I can't comment on what's going wrong there. It looks like you ran the code without first opening a dataset(?).

                  Do you have errors still when running the following code? And if so, where does trace show the error?

                  Code:
                  ssc install summtab
                  sysuse auto, clear
                  summtab, by(foreign) cont_vars(price mpg weight length) cat_vars(rep78) mean median pval landscape replace wordname(summary_table) title(My Table 1)
                  Thanks,
                  John

                  Comment


                  • #10
                    No, it does not work.

                    Code:
                     ssc install summtab
                    checking summtab consistency and verifying not already installed...
                    all files already exist and are up to date.
                    
                    . sysuse auto, clear
                    (1978 Automobile Data)
                    
                    . summtab, by(foreign) cont_vars(price mpg weight length) cat_vars(rep78) mean median pval landscape replace wordname(summary_table) title(My Table 1)
                    r(198);
                    
                    end of do-file
                    
                    r(198);
                    
                    .

                    Comment


                    • #11
                      Thanks for letting me know. What does it show if you run set trace before hand? Where is the error?

                      Code:
                      set trace on
                      ssc install summtab
                      sysuse auto, clear
                      summtab, by(foreign) cont_vars(price mpg weight length) cat_vars(rep78) mean median pval landscape replace wordname(summary_table) title(My Table 1)
                      Edit: You can just show the very last several lines of the trace output. My guess is that something is going on with putdocx, but trace should be able to confirm this.
                      Last edited by John Gallis; 24 Apr 2018, 12:06.

                      Comment


                      • #12
                        Code:
                                 --------------------------------------------------------------------------------------------------------------------------------------------------------------- begin putdocx._docx_table_set_cell ---
                                  - syntax anything(name=cellexplist id=cellexplist equalok) [, font(string) halign(string) valign(string) SHADing(string) bold italic UNDERLine(string) UNDERLine1 STRIKEout script(string) rowspan(rea
                        > l 1) colspan(real 1) span(string) append width(string) height(string) link stocell NFORmat(string) linebreak(string) SMALLCaps ALLCaps *]
                                  - if (`"`rowspan'"' != "1" & `"`span'"' != "") {
                                  = if (`"1"' != "1" & `""' != "") {
                                    opts_exclusive "rowspan() span()"
                                    exit 198
                                    }
                                  - if (`"`colspan'"' != "1" & `"`span'"' != "") {
                                  = if (`"1"' != "1" & `""' != "") {
                                    opts_exclusive "colspan() span()"
                                    exit 198
                                    }
                                  - if `"`underline'"' != "" & `"`underline1'"' != "" {
                                  = if `""' != "" & `""' != "" {
                                    di as err "only one of {bf:underline} or {bf:underline()} is allowed"
                                    exit 198
                                    }
                                  - if `"`underline1'"' != "" {
                                  = if `""' != "" {
                                    local underline "single"
                                    }
                                  - if `"`smallcaps'"' != "" & `"`allcaps'"' != "" {
                                  = if `""' != "" & `""' != "" {
                                    di as err "only one of {bf:smallcaps} or {bf:allcaps} is allowed"
                                    exit 198
                                    }
                                  - local lb `linebreak'
                                  = local lb 
                                  - if `"`lb'"' != "" {
                                  = if `""' != "" {
                                    capture confirm integer number `lb'
                                    if _rc {
                                    di as err "option {bf:linebreak()} requires a positive integer"
                                    exit 198
                                    }
                                    if real(`"`lb'"') < 1 {
                                    di as err "option {bf:linebreak()} requires a positive integer"
                                    exit 198
                                    }
                                    }
                                  - local borders
                                  - local linebreaks 0
                                  - local 0 `anything', `options'
                                  = local 0 , 
                                  - local 0 , `options'
                                  = local 0 , 
                                  - syntax , [BORDer(passthru) linebreak *]
                                  - while !missing(`"`border'`linebreak'"') {
                                  = while !missing(`""') {
                                    if !missing(`"`border'"') {
                                    local borders `borders' `border'
                                    }
                                    if !missing(`"`linebreak'"') {
                                    local ++linebreaks
                                    }
                                    local 0 , `options'
                                    syntax , [BORDer(passthru) linebreak *]
                                    }
                                  - if `"`options'"' != "" {
                                  = if `""' != "" {
                                    di as err "option " `"{bf:`options'}"' " not allowed"
                                    exit 198
                                    }
                                  - if `linebreaks' > 0 & `"`lb'"' != "" {
                                  = if 0 > 0 & `""' != "" {
                                    di as err "only one of {bf:linebreak} and {bf:linebreak()} is allowed"
                                    exit 198
                                    }
                                  - if `"`lb'"' != "" {
                                  = if `""' != "" {
                                    local linebreaks = real(`"`lb'"')
                                    }
                                  - local ckimg = 0
                                  - local cexp `cellexplist'
                                  = local cexp tbl2(18,3) = ("9 (42.9%)")
                                  - if strpos(`"`cexp'"', "=") == 0 {
                                  = if strpos(`"tbl2(18,3) = ("9 (42.9%)")"', "=") == 0 {
                                    local ckimg = 1
                                    }
                                  - else {
                                  - local imgpos = strpos(`"`cexp'"', "=") + 1
                                  = local imgpos = strpos(`"tbl2(18,3) = ("9 (42.9%)")"', "=") + 1
                                  - local bpos = `imgpos' - 1
                                  = local bpos = 13 - 1
                                  - local imgbf = substr(`"`cexp'"', 1, `bpos')
                                  = local imgbf = substr(`"tbl2(18,3) = ("9 (42.9%)")"', 1, 12)
                                  - local imgspec = strtrim(substr(`"`cexp'"', `imgpos', .))
                                  = local imgspec = strtrim(substr(`"tbl2(18,3) = ("9 (42.9%)")"', 13, .))
                                  - local imglen = bstrlen(`"`imgspec'"')
                                  = local imglen = bstrlen(`"("9 (42.9%)")"')
                                  - if substr(`"`imgspec'"', `imglen', 1) != ")" {
                                  = if substr(`"("9 (42.9%)")"', 13, 1) != ")" {
                                    di as err "syntax error"
                                    exit 198
                                    }
                                  - if substr(`"`imgspec'"', 1, 1) == "(" {
                                  = if substr(`"("9 (42.9%)")"', 1, 1) == "(" {
                                  - local ckimg = 1
                                  - }
                                  - else if substr(`"`imgspec'"', 1, 5) == "table" & substr(`"`imgspec'"', 6, 1) == "(" {
                                  = else if substr(`"("9 (42.9%)")"', 1, 5) == "table" & substr(`"("9 (42.9%)")"', 6, 1) == "(" {
                                    local ckimg = 1
                                    }
                                  - else if substr(`"`imgspec'"', 1, 5) == "image" & substr(`"`imgspec'"', 6, 1) == "(" {
                                  = else if substr(`"("9 (42.9%)")"', 1, 5) == "image" & substr(`"("9 (42.9%)")"', 6, 1) == "(" {
                                    if strpos(`"`imgspec'"', ",") != 0 {
                                    di as err "syntax error"
                                    exit 198
                                    }
                                    else {
                                    local imglen = `imglen' - 1
                                    local imgtmp = substr(`"`imgspec'"', 1, `imglen')
                                    local imgstr `imgbf'`imgtmp'
                                    if `"`width'"' != "" {
                                    local imgstr "`imgstr',`width'"
                                    }
                                    else {
                                    local imgstr "`imgstr',0"
                                    }
                                    if `"`height'"' != "" {
                                    local imgstr "`imgstr',`height'"
                                    }
                                    else {
                                    local imgstr "`imgstr',0"
                                    }
                                    if `"`link'"' != "" {
                                    local imgstr "`imgstr',1"
                                    }
                                    else {
                                    local imgstr "`imgstr',0"
                                    }
                                    local imgstr "`imgstr')"
                                    local cellexplist `imgstr'
                                    }
                                    }
                                  - else {
                                    di as err "syntax error"
                                    exit 198
                                    }
                                  - }
                                  - if `ckimg' == 1 {
                                  = if 1 == 1 {
                                  - if `"`width'"' != "" {
                                  = if `""' != "" {
                                    di as err "invalid option " `"{bf:width()}"'"
                                    exit 198
                                    }
                                  - if `"`height'"' != "" {
                                  = if `""' != "" {
                                    di as err "invalid option " `"{bf:height()}"'"
                                    exit 198
                                    }
                                  - if `"`link'"' != "" {
                                  = if `""' != "" {
                                    di as err "invalid option " `"{bf:link}"'"
                                    exit 198
                                    }
                                  - }
                                  - mata: docx_table_set_cell_wrk(`"`font'"', `"`halign'"', `"`valign'"', `"`shading'"', `"`borders'"', `"`bold'"', `"`italic'"', `"`underline'"', `"`strikeout'"', `"`script'"', `rowspan', `colspan', 
                        > `"`span'"', `"`append'"', `"`stocell'"', `"`nformat'"', `linebreaks', `"`smallcaps'"', `"`allcaps'"')
                                  = mata: docx_table_set_cell_wrk(`""', `"center"', `""', `""', `""', `""', `""', `""', `""', `""', 1, 1, `""', `""', `""', `""', 0, `""', `""')
                                  ----------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx._docx_table_set_cell ---
                                - }
                                ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx.docx_table_set ---
                              - }
                              - }
                              ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx.docx_table ---
                            - exit
                            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx ---
                          - if "`excel'" == "excel" {
                          = if "" == "excel" {
                            local s=`r' + 2
                            local letter: word `d' of `c(ALPHA)'
                            qui putexcel `letter'`s' = "`freqperc'", right
                            }
                          - local ++r
                          - local ++k
                          - }
                          - local ++cur_col
                          - local ++m
                          - }
                          - if "`total'" == "total" {
                          = if "" == "total" {
                            if "`incmiss'" != "incmiss" {
                            qui levelsof `cv', local(c_l)
                            }
                            else {
                            qui levelsof `cv', local(c_l) miss
                            }
                            local k = 1
                            local ++d
                            local r=`row'
                            foreach c of local c_l {
                            if "`wts'" != "" {
                            if "`incmiss'" != "incmiss" {
                            qui tab `cv' [aweight=`wts'], matcell(M)
                            }
                            else {
                            qui tab `cv' [aweight=`wts'], matcell(M) miss
                            }
                            local freq_1 = M[`k',1]
                            local freq_1 = strltrim("`freq_1'")
                            qui count if `cv' != .
                            local pt_1 =100*`freq_1'/`r(N)'
                            local pt_1: di %5.1f `pt_1'
                            local pt_1 = strltrim("`pt_1'")
                            local p_m " ("
                            local p_n ")"
                            local perc "%"
                            local freqperc `pt_1'`perc'
                            }
                            else {
                            if "`incmiss'" != "incmiss" {
                            qui tab `cv', matcell(M)
                            }
                            else {
                            qui tab `cv', matcell(M)
                            }
                            local freq_1 = M[`k',1]
                            local freq_1 = strltrim("`freq_1'")
                            qui count if `cv' != .
                            local pt_1 =100*`freq_1'/`r(N)'
                            local pt_1: di %5.1f `pt_1'
                            local pt_1 = strltrim("`pt_1'")
                            local p_m " ("
                            local p_n ")"
                            local perc "%"
                            local freqperc `freq_1'`p_m'`pt_1'`perc'`p_n'
                            }
                            putdocx table tbl2(`r',`d') = ("`freqperc'"), halign(center)
                            if "`excel'" == "excel" {
                            local s=`r' + 2
                            local letter: word `d' of `c(ALPHA)'
                            qui putexcel `letter'`s' = "`freqperc'", right
                            }
                            local ++r
                            local ++k
                            }
                            }
                          - }
                          - else if "`by'" == "" {
                          = else if "foreign" == "" {
                            local r = `row'
                            if "`incmiss'" != "incmiss" {
                            qui levelsof `cv', local(c_l)
                            }
                            else {
                            qui levelsof `cv', local(c_l) miss
                            }
                            local lbe: value label `cv'
                            local k = 1
                            local s=1
                            local v=`j'
                            foreach c of local c_l {
                            local d = `cur_col'
                            if "`lbe'" != ""{
                            local ct: label `lbe' `c'
                            }
                            else {
                            local ct `c'
                            }
                            if "`wts'" != "" {
                            if "`incmiss'" != "incmiss" {
                            qui tab `cv' [aweight=`wts'], matcell(M)
                            }
                            else {
                            qui tab `cv' [aweight=`wts'], matcell(M) miss
                            }
                            local freq_1 = M[`k',`m']
                            local freq_1 = strltrim("`freq_1'")
                            qui count if `cv' != .
                            local pt_1 =100*`freq_1'/`r(N)'
                            local pt_1: di %5.1f `pt_1'
                            local pt_1 = strltrim("`pt_1'")
                            local p_m " ("
                            local p_n ")"
                            local perc "%"
                            local freqperc `pt_1'`perc'
                            }
                            else {
                            if "`incmiss'" != "incmiss" {
                            qui tab `cv', matcell(M)
                            }
                            else {
                            qui tab `cv', matcell(M) miss
                            }
                            local freq_1 = M[`k',`m']
                            local freq_1 = strltrim("`freq_1'")
                            qui count if `cv' != .
                            local pt_1 =100*`freq_1'/`r(N)'
                            local pt_1: di %5.1f `pt_1'
                            local pt_1 = strltrim("`pt_1'")
                            local p_m " ("
                            local p_n ")"
                            local perc "%"
                            local freqperc `freq_1'`p_m'`pt_1'`perc'`p_n'
                            }
                            if `cur_col'==1{
                            putdocx table tbl2(`r',`d') = ("      `ct'"), halign(left) colspan(2)
                            if "`excel'" == "excel" {
                            local s = `r' + 2
                            local letter : word `d' of `c(ALPHA)'
                            qui putexcel `letter'`s' = "      `ct'"
                            }
                            }
                            local ++d
                            putdocx table tbl2(`r',`d') = ("`freqperc'"), halign(center)
                            if "`excel'" == "excel" {
                            local s=`r' + 2
                            local letter: word `d' of `c(ALPHA)'
                            qui putexcel `letter'`s' = "`freqperc'", right
                            }
                            local ++r
                            local ++k
                            }
                            }
                          - local row = `r'
                          = local row = 19
                          - }
                          - qui putdocx describe tbl2
                            ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ begin putdocx ---
                            - version 15.0
                            - if `"`0'"' == `""' {
                            = if `"describe tbl2"' == `""' {
                              di as err "subcommand required"
                              exit 198
                              }
                            - local cmd `0'
                            = local cmd describe tbl2
                            - gettoken do 0 : 0, parse(" ,")
                            - local ldo = length("`do'")
                            = local ldo = length("describe")
                            - if "`do'" == bsubstr("begin",1,max(5,`ldo')) {
                            = if "describe" == bsubstr("begin",1,max(5,8)) {
                              docx_begin `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("paragraph",1,max(9,`ldo')) {
                            = else if "describe" == bsubstr("paragraph",1,max(9,8)) {
                              docx_paragraph `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("text",1,max(4,`ldo')) {
                            = else if "describe" == bsubstr("text",1,max(4,8)) {
                              docx_text `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("table",1,max(5,`ldo')) {
                            = else if "describe" == bsubstr("table",1,max(5,8)) {
                              docx_table `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("image",1,max(5,`ldo')) {
                            = else if "describe" == bsubstr("image",1,max(5,8)) {
                              docx_image `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("pagebreak",1,max(9,`ldo')) {
                            = else if "describe" == bsubstr("pagebreak",1,max(9,8)) {
                              docx_pagebreak `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("describe",1,max(8,`ldo')) {
                            = else if "describe" == bsubstr("describe",1,max(8,8)) {
                            - docx_describe `0'
                            = docx_describe  tbl2
                              -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- begin putdocx.docx_describe ---
                              - syntax [anything]
                              - if `"`anything'"' != "" {
                              = if `"tbl2"' != "" {
                              - gettoken tblnm 0 : 0, parse(" ,")
                              - if `"`0'"' != "" {
                              = if `""' != "" {
                                di as err "invalid " `"`0'"'
                                exit 198
                                }
                              - mata: docx_describe_wrk(`"`tblnm'"', 1)
                              = mata: docx_describe_wrk(`"tbl2"', 1)
                              - }
                              - else {
                                mata: docx_describe_wrk("", 0)
                                }
                              ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx.docx_describe ---
                            - exit
                            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx ---
                          - local droprow = `r(nrows)'-1
                          = local droprow = 20-1
                          - putdocx table tbl2(`r(nrows)',.), drop
                          = putdocx table tbl2(20,.), drop
                            ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ begin putdocx ---
                            - version 15.0
                            - if `"`0'"' == `""' {
                            = if `"table tbl2(20,.), drop"' == `""' {
                              di as err "subcommand required"
                              exit 198
                              }
                            - local cmd `0'
                            = local cmd table tbl2(20,.), drop
                            - gettoken do 0 : 0, parse(" ,")
                            - local ldo = length("`do'")
                            = local ldo = length("table")
                            - if "`do'" == bsubstr("begin",1,max(5,`ldo')) {
                            = if "table" == bsubstr("begin",1,max(5,5)) {
                              docx_begin `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("paragraph",1,max(9,`ldo')) {
                            = else if "table" == bsubstr("paragraph",1,max(9,5)) {
                              docx_paragraph `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("text",1,max(4,`ldo')) {
                            = else if "table" == bsubstr("text",1,max(4,5)) {
                              docx_text `0'
                              exit
                              }
                            - else if "`do'" == bsubstr("table",1,max(5,`ldo')) {
                            = else if "table" == bsubstr("table",1,max(5,5)) {
                            - docx_table `0'
                            = docx_table  tbl2(20,.), drop
                              ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- begin putdocx.docx_table ---
                              - syntax [anything(equalok)] [if] [in] [, *]
                              - mata: docx_is_valid()
                              - local tblinfo `0'
                              = local tblinfo tbl2(20,.), drop
                              - if strpos(`"`tblinfo'"', "=") == 0 {
                              = if strpos(`"tbl2(20,.), drop"', "=") == 0 {
                              - local tblinfo `"`anything'"'
                              = local tblinfo `"tbl2(20,.)"'
                              - docx_table_set `tblinfo', `options'
                              = docx_table_set tbl2(20,.), drop
                                ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- begin putdocx.docx_table_set ---
                                - syntax [anything(equalok)] [, *]
                                - mata: docx_is_valid()
                                - if `"`anything'"' == "" {
                                = if `"tbl2(20,.)"' == "" {
                                  di as err "table or cell specification required"
                                  exit 198
                                  }
                                - local tblinfo `0'
                                = local tblinfo tbl2(20,.), drop
                                - if strpos(`"`tblinfo'"', "=") == 0 {
                                = if strpos(`"tbl2(20,.), drop"', "=") == 0 {
                                - local tblinfo `"`anything'"'
                                = local tblinfo `"tbl2(20,.)"'
                                - local 0 `"`tblinfo'"'
                                = local 0 `"tbl2(20,.)"'
                                - gettoken tblnm 0 : 0
                                - if (strpos(`"`tblnm'"', "(") == 0) {
                                = if (strpos(`"tbl2(20,.)"', "(") == 0) {
                                  di as err "syntax error"
                                  exit 198
                                  }
                                - local tblnm = substr(`"`tblinfo'"', 1, strpos(`"`tblnm'"', "(")-1)
                                = local tblnm = substr(`"tbl2(20,.)"', 1, strpos(`"tbl2(20,.)"', "(")-1)
                                - if (strlen(`"`tblnm'"')!=strlen(strtrim(`"`tblnm'"'))) {
                                = if (strlen(`"tbl2"')!=strlen(strtrim(`"tbl2"'))) {
                                  di as err "syntax error"
                                  exit 198
                                  }
                                - if (substr(strtrim(`"`tblinfo'"'), strlen(strtrim(`"`tblinfo'"')), 1)!=")") {
                                = if (substr(strtrim(`"tbl2(20,.)"'), strlen(strtrim(`"tbl2(20,.)"')), 1)!=")") {
                                  di as err "syntax error"
                                  exit 198
                                  }
                                - mata: docx_table_parse_cell("docx_tname", "docx_tid", "docx_trow", "docx_tcol", "docx_trows", "docx_tcols", `"`tblinfo'"')
                                = mata: docx_table_parse_cell("docx_tname", "docx_tid", "docx_trow", "docx_tcol", "docx_trows", "docx_tcols", `"tbl2(20,.)"')
                                - if `"`docx_trow'"' == "" {
                                = if `"20"' == "" {
                                  di as err "invalid specification; row misspecified"
                                  exit 198
                                  }
                                - if `"`docx_tcol'"' == "" {
                                = if `"."' == "" {
                                  di as err "invalid specification; column misspecified"
                                  exit 198
                                  }
                                - if `"`docx_trow'"' != "." & `"`docx_tcol'"' != "." {
                                = if `"20"' != "." & `"."' != "." {
                                  local options `options' stocell
                                  _docx_table_set_cell `tblinfo', `options'
                                  }
                                - else if `"`docx_trow'"' != "." & `"`docx_tcol'"' == "." {
                                = else if `"20"' != "." & `"."' == "." {
                                - local tblinfo "`docx_tid'_`docx_trow'_`docx_tname'"
                                = local tblinfo "1_20_tbl2"
                                - _docx_table_set_row `tblinfo', `options'
                                = _docx_table_set_row 1_20_tbl2, drop
                                  ---------------------------------------------------------------------------------------------------------------------------------------------------------------- begin putdocx._docx_table_set_row ---
                                  - syntax anything [, NOSPlit addrows(string) drop font(string) halign(string) valign(string) SHADing(string) bold italic UNDERLine(string) UNDERLine1 STRIKEout NFORmat(string) SMALLCaps ALLCaps *]
                                  - if (`"`nosplit'"' != "" & `"`drop'"' != "") {
                                  = if (`""' != "" & `"drop"' != "") {
                                    opts_exclusive "nosplit drop"
                                    exit 198
                                    }
                                  - if (`"`addrows'"' != "" & `"`drop'"' != "") {
                                  = if (`""' != "" & `"drop"' != "") {
                                    opts_exclusive "addrows() drop"
                                    exit 198
                                    }
                                  - if `"`underline'"' != "" & `"`underline1'"' != "" {
                                  = if `""' != "" & `""' != "" {
                                    di as err "only one of {bf:underline} or {bf:underline()} is allowed"
                                    exit 198
                                    }
                                  - if `"`underline1'"' != "" {
                                  = if `""' != "" {
                                    local underline "single"
                                    }
                                  - if `"`smallcaps'"' != "" & `"`allcaps'"' != "" {
                                  = if `""' != "" & `""' != "" {
                                    di as err "only one of {bf:smallcaps} or {bf:allcaps} is allowed"
                                    exit 198
                                    }
                                  - local borders
                                  - local 0 `anything', `options'
                                  = local 0 1_20_tbl2, 
                                  - local 0 , `options'
                                  = local 0 , 
                                  - syntax , [BORDer(passthru) *]
                                  - while !missing(`"`border'"') {
                                  = while !missing(`""') {
                                    local borders `borders' `border'
                                    local 0 , `options'
                                    syntax , [BORDer(passthru) *]
                                    }
                                  - if `"`options'"' != "" {
                                  = if `""' != "" {
                                    di as err "option " `"{bf:`options'}"' " not allowed"
                                    exit 198
                                    }
                                  - mata: docx_table_set_row_wrk(`"`anything'"', `"`nosplit'"', `"`addrows'"', `"`drop'"', `"`font'"', `"`halign'"', `"`valign'"', `"`shading'"', `"`borders'"', `"`bold'"', `"`italic'"', `"`underline'
                        > "', `"`strikeout'"', `"`nformat'"', `"`smallcaps'"', `"`allcaps'"')
                                  = mata: docx_table_set_row_wrk(`"1_20_tbl2"', `""', `""', `"drop"', `""', `""', `""', `""', `""', `""', `""', `""', `""', `""', `""', `""')
                                  ------------------------------------------------------------------------------------------------------------------------------------------------------------------ end putdocx._docx_table_set_row ---
                                  }
                                  else if `"`docx_trow'"' == "." & `"`docx_tcol'"' != "." {
                                  local tblinfo "`docx_tid'_`docx_tcol'_`docx_tname'"
                                  _docx_table_set_col `tblinfo', `options'
                                  }
                                  else {
                                  local options `options' rrange(`"`docx_trows'"') crange(`"`docx_tcols'"')
                                  _docx_table_set_cell_range `tblinfo', `options'
                                  }
                                  }
                                ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx.docx_table_set ---
                                }
                              ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx.docx_table ---
                              exit
                              }
                            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end putdocx ---
                          ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end summtab ---
                        r(198);
                        
                        end of do-file
                        
                        r(198);

                        Comment


                        • #13
                          Thank you, Alexander! It's looking like some type of putdocx-related error. Please send me the entire trace output (either as an uploaded attachment on a post here or to my email [see help summtab for my email address]) and I will take a closer look.

                          Comment


                          • #14
                            mail

                            Comment


                            • #15
                              Hi, John. I have the same problem with Alex. I am wondering whether the issue has been solved now? Thank you for your reply.

                              Comment

                              Working...
                              X