Announcement

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

  • Announcing table1_mc: Stata module to create "Table 1" of baseline characteristics for a manuscript

    Dear Statalisters,

    I have just posted my program table1_mc on SSC (requires version 14.2). This program is essentially an extension of Phil Clayton’s table1 command.

    . sysuse auto, clear
    (1978 Automobile Data)

    . generate much_headroom = (headroom>3)

    . table1_mc, by(foreign) vars(price conts \ price contln %5.0f %4.2f \ weight contn %5.0f \ rep78 cate \ much_headroom bine)

    +------------------------------------------------------------------------------------+
    | Level Domestic Foreign p-value |
    |------------------------------------------------------------------------------------|
    | N=52 N=22 |
    |------------------------------------------------------------------------------------|
    | Price 4,782.5 (4,184-6,234) 5,759 (4,499-7,140) 0.30 |
    | Price 5534 (×/1.50) 5959 (×/1.44) 0.46 |
    |------------------------------------------------------------------------------------|
    | Weight (lbs.) 3317 (695) 2316 (433) <0.001 |
    |------------------------------------------------------------------------------------|
    | Repair Record 1978 1 2 ( 4%) 0 ( 0%) <0.001 |
    | 2 8 (17%) 0 ( 0%) |
    | 3 27 (56%) 3 (14%) |
    | 4 9 (19%) 9 (43%) |
    | 5 2 ( 4%) 9 (43%) |
    |------------------------------------------------------------------------------------|
    | much_headroom 28 (54%) 2 ( 9%) <0.001 |
    +------------------------------------------------------------------------------------+
    Data are presented as mean (SD) or geometric mean (×/GSD) or median (IQR) for continuous measures, and frequency (percentage) for categorical measures.


    Feedback welcome.

    Best wishes, Mark
    Last edited by Mark Chatfield; 02 Jun 2017, 02:17.

  • #2
    Of course, the output does in reality look much nicer than that in my first post...
    Click image for larger version

Name:	output for Statalist.png
Views:	1
Size:	26.9 KB
ID:	1399400

    Comment


    • #3
      Hi Mark- looks great! Any plans for adding support for the -svy- prefix, as it's a lapse for all the options?
      __________________________________________________ __
      Assistant Professor, Department of Biostatistics and Epidemiology
      School of Public Health and Health Sciences
      University of Massachusetts- Amherst

      Comment


      • #4
        Hi Mark,

        I have looked the code and tried to add option table(before|after) is not working. I think this option is not implemented. In addition it should be helpful if the each factors N (denominator) will be added in the same table after each variable instead of a separate table.

        Comment


        • #5
          Is there a way to use this command or the older Table1 command on survey data (e.g. with the svy command) We desperately need that

          Comment


          • #6
            Hi Ruth, fweights are allowed ... which would only help with the simplest survey data. That's all I'm afraid.

            Comment


            • #7
              of the various use-written commands in this area, I believe that only -meantab- accepts pweights; whether it also does everything else you want, I'm not sure; use -search- to find and download

              Comment


              • #8
                Thanks Mark, I have a couple more follow up questions:

                1. What are the differences/advantages of using the table1_mc command/option over the older table1 command? and

                2. Is there a way using either command to stratify by more than one variable e.g. when using: by(varname) and not by(var1 var2). For example, I used the following code to stratify by immigrant status:

                table1, by (immig_status) vars(age contn \ sex bin \ marital_stat cat \ race cat \ education cat \ income cat \) onecol

                However, I would like to stratify by both immigrant status and sex. (see table below) What would be the best way to go about this? Any suggestions for/modifications to the above code to be able to do this?


                Click image for larger version

Name:	Screen Shot 2018-03-29 at 1.16.53 AM.png
Views:	1
Size:	38.5 KB
ID:	1436624

                Comment


                • #9
                  Hi Ruth
                  1. table1_mc is an extension and improvement on table1. For more, type . viewsource table1_mc.ado
                  2. You would need to use either command twice.

                  Comment


                  • #10
                    Thank you. For number 2, I just did the following:

                    table1_mc if immig_status==1, by (sex) vars(age contn \ marital_stat cat \ race cat \ education cat \ income cat \) onecol
                    table1_mc if immig_status==0, by (sex) vars(age contn \ marital_stat cat \ race cat \ education cat \ income cat \) onecol

                    These gave me two different tables which were exported into excel and I then manually filled the table above by copying and pasting side by side into one excel sheet to look like the sample table above.

                    Comment


                    • #11
                      I have just become aware of the user written -tabxml- command, which can deal with survey data.

                      net install sg100, from(http://www.stata.com/stb/stb47)
                      *to avoid matsum error message

                      net install tabxml.pkg

                      Comment


                      • #12
                        Thanks Mark, Sorry about the super late reply on this, I thought I replied. The tabxml worked great for me.

                        Comment


                        • #13
                          Hi Mark

                          Can this command be used to compare three groups or only two. For example, if I have three groups and I compare means between them, is the program running a ttest or anova. I believe the program accurately runs an anova but I just wanted to be sure.

                          Steven

                          Comment


                          • #14
                            Hi Steven,

                            I know of comparing three groups. I believe you can use the
                            Code:
                            split(varname)
                            option to do that...(I don't get a p-value for comparing two groups if that helps) If anyone has been able to figure out how to get the significance levels for that, it would be nice, otherwise, I use the option:
                            Code:
                            display
                            to get the p-values in the display window and manually enter them in your table. Hope this helps

                            Comment


                            • #15
                              On another note, I am using tabxml in Stata 14.2 and trying to do another Table 1 by sex. When using variations of this code:

                              Code:
                               tabxml, ivc(age_p) ivd(sex_r married racreci3 edu_cat poor2 emp_stat notcov usupl) order(age_p sex_r racreci3 married edu_cat poor2 emp_stat notcov usupl) save("/location_filename_$datentime") split(sex_r) options(n per) display bold justify(c) pval sp
                              I keep getting errors such as: "invalid subpop() option" when I try using the subcond option. I also get this error:

                              Code:
                              Table contains a zero in the marginals.
                                Statistics cannot be computed.
                              conformability error
                              r(503);
                              when I use this code:

                              Code:
                               tabxml, ivc(age_p) ivd(sex_r married racreci3 edu_cat poor2 emp_stat notcov usupl) order(age_p sex_r racreci3 married edu_cat poor2 emp_stat notcov usupl) save("/location_filename_$datentime") split(sex_r) options(n per) display bold justify(c) pval sp
                              What am I doing wrong?

                              Comment

                              Working...
                              X