Announcement

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

  • New package basetable

    Hi
    I've done a new package for Stata called basetable.

    Most researchers where I work have to make at least one basetable comparing eg several possible confounders for each level of a risk factor or another categorical variable.
    Building these tables is usually very tedious to do.
    They are necessary for the upcoming article and they are often also bound to be changed during writing process.

    This tools both eases the making of the table at the cost of some minor simplifications and also makes it possible to export the resulting table to excel using only one (1!) single command.
    And hence if variable labels as well as value labels are set smart from the beginning then only minor changes are needed before using the table directly in the word document containing the upcoming article.

    If you are interested please read the help file carefully. Only there is the full description of the functionality.

    An example below using low as the categorical variable for the column comparing age, ftv2, race and smoke and then putting the table into the excel workbook "./tables.xls" at sheet "Table 1" as well as showing the table in the log:

    Code:
    . basetable low age(%6.2f) ftv2(1) race(1) smoke(Yes), nolog toxl(./tables.xls, Tabel 1, 1, 1)
    
    +------------------------------------------------------------------------------------------------+
    |                                                            |Normal       Low          |P-value |
    |------------------------------------------------------------+--------------------------+--------|
    |n (pct)                                                     |130 (68.8)   59 (31.2)    |        |
    |age of mother, mean (sd)                                    |23.66 (5.58) 22.31 (4.51) |0.1031  |
    |number of visits to physician during 1st trimester, n (pct) |                          |        |
    |    0_visits                                                |64 (49.2)    36 (61.0)    |        |
    |    1_visits                                                |36 (27.7)    11 (18.6)    |        |
    |    2_visits                                                |23 (17.7)    7 (11.9)     |        |
    |    >3_visits                                               |7 (5.4)      5 (8.5)      |0.2747  |
    |race, n (pct)                                               |                          |        |
    |    white                                                   |73 (56.2)    23 (39.0)    |        |
    |    black                                                   |15 (11.5)    11 (18.6)    |        |
    |    other                                                   |42 (32.3)    25 (42.4)    |0.0819  |
    |smoked during pregnancy (Yes), n (pct)                      |44 (33.8)    30 (50.8)    |0.0265  |
    +------------------------------------------------------------------------------------------------+
    Table send to Excel succesfully...
    To install just write -ssc install basetable- at the command promt.
    And -help basetable- to read about usage.


    Enjoy
    Last edited by Niels Henrik Bruun; 12 May 2015, 05:52.
    Kind regards

    nhb

  • #2
    please explain how your program is different from (better than) the already existing table1.ado (also at SSC)

    Comment


    • #3
      Hi
      I didn't knew of the existence of -table1-
      They are indeed very similar.

      -table1- can better specify comparing test.
      -table1- handles if, in and weights, -basetable- doesn't (for now).
      -table1- can take missings into the table.

      -basetable- can save the tables more freely in the excelbook, eg specify sheet name and place at sheet. Also -basetable- can save more tables in 1 excelbook
      -basetable- can hide count less than 5 in tables.
      -basetable- can present row percentages instead of column percentages.

      The list isn't complete. But this is what I've found so far.
      Kind regards

      nhb

      Comment


      • #4
        thank you

        Comment


        • #5
          Hi
          There has been an update to the package basetable.
          It now also reports rowtotals as well as a missing report, eg:
          Code:
          . use "http://www.stata-press.com/data/r13/hospid2.dta", clear
          . *Add some missings
          . label define low 0 "Normal" 1 "Low"
          . label values low low
          . replace low = . in 4/6
          (3 real changes made, 3 to missing)
          . replace age = . in 5/8
          (4 real changes made, 4 to missing)
          . replace race = . in 3/8
          (6 real changes made, 6 to missing)
          
          . forvalues val = 0/6 {
            2. label define ftv `val' "`val'_visits", add
            3. }
          . label values ftv ftv
          . label define smoke 0 "No" 1 "Yes"
          . label values smoke smoke
          . label variable ftv "Visits to physician"
          
          . capture rm "./tables.xls"
          
          . basetable low age(%6.2f) ftv(0) race(0) smoke(Yes), nolog toxl(./tables.xls, Tabel 2, 1, 1) continousreport(iqr)
          
          +-------------------------------------------------------------------------------------------------------------+
          |                                       |Normal       Low          |Total        |P-value |Missings / N (Pct) |
          |---------------------------------------+--------------------------+-------------+--------+-------------------|
          |n (pct)                                |127 (68.3)   59 (31.7)    |186          |        |3 / 189 (  1.59)   |
          |age of mother, median (iqr)            |23.00 (9.00) 22.00 (6.00) |23.00 (7.00) |0.2444  |4 / 189 (  2.12)   |
          |Visits to physician, n (pct)           |                          |             |        |                   |
          |    0_visits                           |62 (63.3)    36 (36.7)    |98           |        |                   |
          |    1_visits                           |35 (76.1)    11 (23.9)    |46           |        |                   |
          |    2_visits                           |23 (76.7)    7 (23.3)     |30           |        |                   |
          |    3_visits                           |< 5 ()       < 5 ()       |7            |        |                   |
          |    4_visits                           |< 5 ()       < 5 ()       |4            |        |                   |
          |    6_visits                           |< 5 ()       0 (0.0)      |1            |0.3020  |0 / 189 (  0.00)   |
          |race, n (pct)                          |                          |             |        |                   |
          |    white                              |71 (75.5)    23 (24.5)    |94           |        |                   |
          |    black                              |14 (56.0)    11 (44.0)    |25           |        |                   |
          |    other                              |39 (60.9)    25 (39.1)    |64           |0.0625  |6 / 189 (  3.17)   |
          |smoked during pregnancy (Yes), n (pct) |41 (32.3)    30 (50.8)    |71           |0.0153  |0 / 189 (  0.00)   |
          +-------------------------------------------------------------------------------------------------------------+
          Table send to Excel succesfully...
          I hope you like it
          Kind regards

          nhb

          Comment


          • #6
            Hi
            Thanks to Kit Baum a new version 1.3.4 of basetable is present at ssc.

            First of all all code including mata has been moved to the ado-file.
            This way what is done is fully documented.
            Further there has been some using problems using the mlib in other Stata version than 13.1
            So far as I've been able to test it, basetable works from Stata 13 and onwards (working on going back to Stata 12).

            New things in basetable:
            • if and in are possible at the end of the command
            • The part of the command that specifies row and column percentages now accept 0, r or R instead of just 0 and 1, c, C instead of just 1
            • Lokal type of summary for continous variables can now be specified
            • It is possible to replace sheet
            • pi - prediction interval for continous variables
            • iqi - interquartile interval for continous variables
            • Error handling is improved. Errors are shown in the table
            • Hidesmall works on totals
            • Headers for groups of variables, eg socioeconomics variables is possible
            • Logging optional is now optional, hence the movement of errors to the table
            • Missing table is now optionalThank you to Georgios Bouliotis, Richard Goldstein, Eric Melse and Pia Deichgraeber for comments.
            What you can do is still interactively build basetable from a single command like below:

            Code:
                    . basetable low (Continous,***) age(%6.0f,iqr) age(%6.0f,iqi) (***,***) (Categorical) ftv(c) race(c) if smoke == 1 in 100/180
                    +-------------------------------------------------------------------------------------------------------------------+
                    |                                                                   |Normal      |Low         |Total       |P-value |
                    |-------------------------------------------------------------------+------------+------------+------------+--------|
                    |n (pct)                                                            |41 (57.7)   |30 (42.3)   |71          |        |
                    |Continous                                                          |***         |***         |***         |***     |
                    |age of mother, median (iqr)                                        |21 (9)      |22 (6)      |22 (7)      |0.9133  |
                    |age of mother, median (iqi)                                        |21 (19; 28) |22 (20; 26) |22 (19; 26) |0.9133  |
                    |***                                                                |***         |***         |***         |***     |
                    |Categorical                                                        |            |            |            |        |
                    |number of visits to physician during 1st trimester, n (column pct) |            |            |            |        |
                    |    0_visits                                                       |23 (56.1)   |20 (66.7)   |43          |        |
                    |    1_visits                                                       |6 (14.6)    |5 (16.7)    |11          |        |
                    |    2_visits                                                       |9 (22.0)    |2 (6.7)     |11          |        |
                    |    3_visits                                                       |1 (2.4)     |3 (10.0)    |4           |        |
                    |    4_visits                                                       |1 (2.4)     |0 (0.0)     |1           |        |
                    |    6_visits                                                       |1 (2.4)     |0 (0.0)     |1           |0.2873  |
                    |race, n (column pct)                                               |            |            |            |        |
                    |    white                                                          |31 (81.6)   |19 (63.3)   |50          |        |
                    |    black                                                          |3 (7.9)     |6 (20.0)    |9           |        |
                    |    other                                                          |4 (10.5)    |5 (16.7)    |9           |0.2130  |
                    +-------------------------------------------------------------------------------------------------------------------+
            When tables is acceptable, it can be send to sheets in an excelbook.

            -Basetable- relies on that variable labels and when meaningfull value labels are set for all used variables.

            Hope you enjoy it
            Kind regards

            nhb

            Comment


            • #7
              Thanks to Kit Baum there is an update of basetable at ssc.
              New features are:
              • Local conditioning with headers in table, eg if one only want to report a set variables wrt males, but the rest should be done for both genders
              • Integration to log2markup - ie output can be styled as csv, html, latex markdown or smcl and saved in a file by specifying the using modifier
              • Basetable can now be used also for Stata version 12. However the option toxl is removed from version 12. Instead one can use style csv and the using modifier to export table into an excel readable file
              Enjoy
              Kind regards

              nhb

              Comment


              • #8
                Thanks to Kit Baum is there a new update of basetable.

                Basetable now uses the same mata library as my other package matrixtools. This way they both have become more integrated with log2markup

                This means that if both packages are installed then they must be installed with
                Code:
                ssc install packagename, replace
                and it would be
                an good idea to update both at the same time.

                What is new in this version is a binomial 95% CI and the option to format counts with a thousand separator.

                What's also new is that in time more and more examples will appear on my homepage for Stata.
                The homepage is mainly generated by markdown commented do files transformed by log2markup and then MkDocs

                Enjoy
                Kind regards

                nhb

                Comment


                • #9
                  Thanks to Kit Baum is there a new update of basetable..
                  Features are described at my homepage
                  Kind regards

                  nhb

                  Comment


                  • #10
                    Thanks to Kit Baum is there a new update of basetable..
                    Kind regards

                    nhb

                    Comment


                    • #11
                      Thanks to Kit Baum is there a new update of basetable at SSC..
                      Details at http://www.bruunisejs.dk/StataHacks/...asetable_demo/
                      Kind regards

                      nhb

                      Comment


                      • #12
                        Thanks to Kit Baum there is a new update.
                        Kind regards

                        nhb

                        Comment


                        • #13
                          Originally posted by Niels Henrik Bruun View Post
                          Thanks to Kit Baum there is a new update.
                          Hello Niels, thanks ideed for this wonderful program, it deserves to become one of the hottest in ssc. I have just one question/sugesstion that may interest you.

                          Right now reporting 95%CIs for categorical variables is little cumbersome as each of the categories need to be repeated with the variable names.
                          Code:
                          basetable low race(white,ci) race(black,ci) race(hispanic,ci)
                          This is not a problem for variables with small number of categories, but in real life data things can look far more complex...
                          Code:
                          basetable low  europe(italia,ci) europe(spain,ci) europe(france,ci).......
                          If CIs can be calculated in the same manner as n(%) without having to repeat the categories, the program can look far more user-friendly.

                          Comment


                          • #14
                            Sonnen Blume Thank you for your kind words and your suggestion.
                            I will look into it.
                            Only by getting suggestions will the basetable remain a useful tool, so thank you very much
                            Kind regards

                            nhb

                            Comment


                            • #15
                              Originally posted by Niels Henrik Bruun View Post
                              Sonnen Blume Thank you for your kind words and your suggestion.
                              I will look into it.
                              Only by getting suggestions will the basetable remain a useful tool, so thank you very much
                              Thanks. Looking forward to it. Please also check the compatibility with putdocx if possible.

                              Comment

                              Working...
                              X