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, 01:17.

  • Mark Chatfield
    replied
    Hi Magnus

    It is possible. The key to seeing this is in . help table1_mc_dta2docx (Description).

    sysuse auto, clear
    table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate) extraspace clear
    rename N_* n_*
    order n_0, before(foreign_0)
    order n_1, before(foreign_1)
    table1_mc_dta2docx using "H:\example Table 1.docx", replace

    BW,
    Mark

    Leave a comment:


  • Magnus Lyngbakken
    replied
    Hi,

    This is a really great extension, thank you for the time and work invested. Is there a way to include number of valid observations (N) directly to the table output? Like this:

    Click image for larger version

Name:	table.png
Views:	1
Size:	46.1 KB
ID:	1525480


    I manage to compile two separate tables, one with N_0, N_1, m_0 and m_1, and one with the actual data, but it would save time and editing if these could be combined.

    Best regards,
    Magnus

    Leave a comment:


  • Mark Chatfield
    replied
    help tabulate twoway explains that the syntax in my program (or in a simple . tab cat1 cat2, exact command) needs to be something like . tab cat1 cat2, exact(2). To quote: The optional positive
    integer # is a multiplier on the amount of memory that the command is permitted to consume.
    The default is 1. This option should not be necessary for reasonable r x c tables. If the
    command terminates with error 910, try exact(2). The maximum row or column dimension allowed
    when computing Fisher's exact test is the maximum row or column dimension for tabulate (see
    limits).

    Leave a comment:


  • bln tfte
    replied
    hi Mark,
    When I use "cate" in table1_mc for Fisher's test incase categories have small numbers, I am getting an error meassage that says " exceeded memory limits using exact(1); try again with larger #;........"
    Any advice?

    Leave a comment:


  • Steven Spivack
    replied
    Ok thanks so much for this tip.

    Leave a comment:


  • Ruth-Alma Turkson-Ocran
    replied
    Steven Spivack Sorry for the delayed response. I used the option display while running the tabxml command. This lets you see the output for all the different tests being run to create the table. In the output window, I just scrolled through to find the test I was looking for and its associated p-value and put the p-value in my table - yes tedious, but was the only option I saw.

    Unfortunately, I have not yet used the testparm command, so I cannot comment on that.

    Leave a comment:


  • Steven Spivack
    replied
    Originally posted by Ruth-Alma Turkson-Ocran View Post
    [USER="18711"]I find that when I examine continuous variables, I do not get the p-values (I can get them from the output window when I use the display command). I get the codes with the categorical/dichotomous variables. I also have to sometimes run it a few times differently to get what I want because some variables end up missing in the Excel output--To expand: I run it once with only continuous variables, then I run it again with only categorical variables and then copy/paste/rearrange in the Excel output, and save.
    I am not getting p values for any continuous variables either with tabxml. Instead, do you just regress each IV on the DV and then use the testparm command to get a p value, that is what I am doing now but it is not super efficient.

    Leave a comment:


  • Ruth-Alma Turkson-Ocran
    replied
    Steven Spivack No; I did not use the osvy option. My dataset is a survey with pweights so I svyset the data prior to using, so I left out the osvy option.

    UPDATE: I also believe I fixed my issue. I think the sex variable was tripping me up as I was trying to examine sex differences. So the code that worked for me was:

    Code:
    tabxml, dv(sex_r) ivc(age_p) ivd(married edu_cat poor2 emp_stat notcov usupl) order(age_p married edu_cat poor2 emp_stat notcov usupl) save("/location_filename_$datentime") display bold justify(c) subcond(black_african==1) pval sp
    I also like Table1, but its huge disadvantage is that it just does not work with weights.

    Regarding tabxml, I find that when I examine continuous variables, I do not get the p-values (I can get them from the output window when I use the display command). I get the codes with the categorical/dichotomous variables. I also have to sometimes run it a few times differently to get what I want because some variables end up missing in the Excel output--To expand: I run it once with only continuous variables, then I run it again with only categorical variables and then copy/paste/rearrange in the Excel output, and save.

    Leave a comment:


  • Steven Spivack
    replied
    Originally posted by Ruth-Alma Turkson-Ocran View Post
    What am I doing wrong?
    Did you use the osvy option? Have you installed dm49 which is required for tabxml?
    Last edited by Steven Spivack; 23 Oct 2018, 23:45.

    Leave a comment:


  • Steven Spivack
    replied
    Thanks again Ruth-Alma. I like the Table1 and tabout commands because they are so efficient and allow for ANOVA and Chi2, so I was hoping they would allow the use of aweights. It looks like tabxml does not allow for weights either when the data are not svyset.

    I am aware of these other commands but they are so much more tedious since I have to create 5 distinct descriptive tables which are quite long.
    Last edited by Steven Spivack; 23 Oct 2018, 23:44.

    Leave a comment:


  • Ruth-Alma Turkson-Ocran
    replied
    Steven Spivack Depending on what you want to examine, the following commands can handle analytic weights:

    tabstat (aweights, fweights)

    tabulate (aweights , fweights ) ...also goes with summarize...

    table ( fweights, iweights, and pweights)

    These are the few that come to mind...

    Leave a comment:


  • Steven Spivack
    replied
    Thanks for these examples. I am running into another problem with the table1 command though, which is that it does not appear to allow for the use of analytical weights. Do you know of another command that allows for this? I tried tabout but you need to survey set the data first which is not applicable for these analyses.

    Leave a comment:


  • Ruth-Alma Turkson-Ocran
    replied
    I forgot to add a sample of the dataset:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(age_p sex_r married edu_cat poor2 emp_stat) byte notcov float(usupl stay_us black_african)
    80 0 0 1 1 0 2 1 . 0
    56 0 1 3 3 0 2 1 1 0
    46 0 1 3 3 1 2 1 . 0
    22 0 0 2 3 1 2 1 . 0
    31 0 0 2 3 0 2 1 . 0
    56 0 0 1 3 1 2 1 . 0
    58 0 0 3 3 1 2 1 . 0
    55 0 0 2 1 0 2 1 . 0
    56 0 1 3 3 0 2 1 . 0
    58 0 1 1 2 0 2 1 . 0
    78 0 0 1 2 0 2 1 2 0
    62 0 1 1 3 0 2 1 . 0
    33 0 0 2 3 1 2 0 . 0
    59 0 1 1 3 1 1 0 . 0
    68 0 0 2 1 0 2 1 . 0
    20 0 0 1 1 0 1 1 . 0
    73 0 0 1 2 0 2 1 . 0
    64 0 0 2 3 1 2 1 . 0
    67 0 0 3 2 1 2 0 . 0
    55 0 0 3 3 0 1 0 . 0
    60 0 0 3 3 1 2 1 . 0
    62 0 0 1 2 0 1 1 . 0
    27 0 0 2 3 1 1 0 . 0
    76 0 0 . 3 0 2 1 1 1
    51 0 0 1 3 1 1 0 . 0
    35 0 0 2 3 1 2 1 2 1
    34 0 1 3 3 1 2 1 . 0
    45 0 1 1 3 0 1 1 . 0
    67 0 0 3 3 0 2 1 2 0
    24 0 0 3 3 0 2 1 . 0
    48 0 0 3 3 1 2 1 . 0
    38 0 0 1 3 0 2 1 2 1
    27 0 0 3 3 1 2 1 . 0
    54 0 0 1 2 1 2 1 . 0
    61 0 0 1 2 0 2 1 . 0
    33 0 1 3 3 1 2 1 . 0
    56 0 0 1 2 1 2 1 . 0
    28 0 0 2 1 0 2 1 . 0
    77 0 0 2 3 0 2 1 . 0
    81 0 0 1 3 0 2 1 . 0
    32 0 0 2 2 1 2 1 2 1
    58 0 1 2 3 1 2 1 . 0
    50 0 1 1 3 0 2 1 . 0
    35 0 1 2 2 0 2 1 . 0
    52 0 0 3 3 1 2 1 . 0
    59 0 1 3 3 1 2 1 . 0
    35 0 1 . 1 0 1 0 2 0
    59 0 0 1 1 0 2 1 . 0
    50 0 1 1 3 1 2 1 . 0
    29 0 0 1 1 0 2 1 2 1
    52 0 0 1 3 1 2 1 2 0
    25 0 0 1 3 1 2 1 . 0
    59 0 0 2 3 1 2 1 . 0
    30 0 0 1 1 1 2 1 1 1
    36 0 1 2 3 0 2 1 . 0
    28 0 0 2 2 1 1 0 . 0
    53 0 1 2 2 0 1 1 . 0
    25 0 1 3 2 0 2 0 . 0
    28 0 0 1 1 1 2 1 2 0
    34 0 1 3 3 1 2 1 1 0
    46 0 0 1 2 0 2 1 . 0
    35 0 1 1 3 1 1 0 2 1
    78 0 0 1 2 0 2 1 . 0
    81 0 1 2 3 0 2 1 . 0
    32 0 1 3 3 1 2 1 . 0
    30 0 0 2 2 1 1 1 . 0
    20 0 0 2 1 1 1 1 1 1
    70 0 1 2 3 0 2 1 . 0
    30 0 1 1 1 1 2 0 1 1
    38 0 0 3 3 1 2 1 . 0
    36 0 0 1 2 1 2 0 1 1
    78 0 0 1 3 0 2 1 . 0
    74 0 0 1 2 0 2 1 . 0
    27 0 0 2 3 1 1 0 . 0
    44 0 0 1 3 1 1 0 . 0
    65 0 1 2 3 0 2 1 . 0
    36 0 0 2 3 1 2 1 . 0
    25 0 0 2 1 0 2 1 . 0
    63 0 0 2 2 0 1 0 . 0
    32 0 0 3 3 1 2 1 . 0
    71 0 1 1 3 0 2 1 . 0
    82 0 1 1 3 0 2 1 . 0
    65 0 1 1 3 1 2 1 . 0
    46 0 1 2 2 1 1 0 . 0
    31 0 0 3 1 0 2 1 1 1
    55 0 1 1 3 1 1 0 2 1
    55 0 1 1 2 0 1 1 2 0
    57 0 1 2 2 0 2 1 . 0
    27 0 1 2 3 1 2 1 2 1
    37 0 1 2 3 1 2 1 . 0
    31 0 0 1 3 1 1 1 1 0
    69 0 0 2 2 0 2 1 . 0
    21 0 0 1 1 0 1 1 . 0
    20 0 0 2 3 1 2 0 . 0
    60 0 0 3 3 0 2 1 . 0
    36 0 1 1 2 1 1 1 2 1
    36 0 1 3 2 1 2 1 . 0
    24 0 0 1 3 0 1 0 . 0
    66 0 0 2 2 1 2 1 . 0
    26 0 1 1 1 1 1 1 . 0
    end
    label values age_p pep031x
    label values sex_r sex_r
    label def sex_r 0 "0: Females", modify
    label values married married
    label def married 0 "0: Not Married", modify
    label def married 1 "1: Currently Married", modify
    label values edu_cat edu_cat
    label def edu_cat 1 "1: High School", modify
    label def edu_cat 2 "2: College", modify
    label def edu_cat 3 "3: Graduate School", modify
    label values poor2 poor2
    label def poor2 1 "1: Poor", modify
    label def poor2 2 "2: Near Poor", modify
    label def poor2 3 "3: Not Poor/Near Poor", modify
    label values emp_stat emp_stat
    label def emp_stat 0 "0: Unemployed", modify
    label def emp_stat 1 "1: Employed", modify
    label values notcov pep394x
    label def pep394x 1 "1 Not covered", modify
    label def pep394x 2 "2 Covered", modify
    label values usupl usupl
    label def usupl 0 "0: Do not have a usual place", modify
    label def usupl 1 "1: Have a usual place", modify
    label values stay_us stay_us
    label def stay_us 1 "1: ≥ 5 yrs but < 10 yrs", modify
    label def stay_us 2 "2: ≥ 10 years", modify
    label values black_african black_african
    label def black_african 0 "0: Not Black African", modify
    label def black_african 1 "1: Black African", modify
    Also, please delete racreci3 from the code in the previous post. The true code should be:

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

    Leave a comment:


  • Ruth-Alma Turkson-Ocran
    replied
    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?

    Leave a comment:

Working...
X