Announcement

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

  • #31
    Dear Mark,

    I have tried many times to get the p-value of some binary variables, I get the p-values from the categorical variables, but I also need for the binary. Can you please help me and tell what I am doing wrong here?
    table1_mc, by(sex) vars(education cat \ income cat \ diabetes bin \ stroke bin \ heart_attack bin \ smoke bin) nospace clear

    Thanks in advance!

    -Kate

    Comment


    • #32
      Kate Underwood
      You might like to try table1 template of asdocx. Here are some key features of table1 template:
      1. You can control the statistics used with binary, categorical , and continuous variables.
      2. You can control the test (ttest, Chi2, etc) used with each type of variables.
      3. The template can be used with and without survey weights.
      4. Binary variables can be treated as categorical variables or continuous variables.
      5. Percentages can be based on row total, column total or grand total
      6. The output can be sent to .docx, .xlsx, or .tex format.

      Here is an example output:
      Code:
      asdocx svy: tab vision denied police discouraged ///
                 i.fired eds bskin wskin disc , factor(N %) template(table1)   replace
      Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	125.9 KB
ID:	1594403

      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #33
        Hi Mark. For some reason my percentages aren't reporting and adding 'catrowperc' doesn't work or I am doing it wrong but my code and output are as follows. Any idea what I'm doing wrong? Thank you.

        Code:
        table1_mc, by(condition) vars(dem_age cat %2.2f) total(after) nospace onecol missing
        
        +--------------------------------------------------------------------------------------------------------------+
          |            Control    Medical Framing   Strengths Framing   Medical & Strengths Framing   Total      p-value |
          |--------------------------------------------------------------------------------------------------------------|
          |            N=155      N=159             N=158               N=149                         N=621              |
          |--------------------------------------------------------------------------------------------------------------|
          | dem_age                                                                                               0.83   |
          |    18-25   53 (%)     47 (%)            56 (%)              48 (%)                        204 (%)            |
          |    26-35   51 (%)     65 (%)            62 (%)              51 (%)                        229 (%)            |
          |    35-45   29 (%)     30 (%)            24 (%)              28 (%)                        111 (%)            |
          |    46-55   12 (%)     8 (%)             6 (%)               13 (%)                        39 (%)             |
          |    56-65   7 (%)      8 (%)             9 (%)               8 (%)                         32 (%)             |
          |    66+     3 (%)      1 (%)             1 (%)               1 (%)                         6 (%)              |
          +--------------------------------------------------------------------------------------------------------------+

        Comment


        • #34
          Code:
          Bob Geldof  %2.2f   is what is causing your problem. Remove, or improve this to e.g. %3.2f 
          Kate Underwood  you have not given enough information for me to problem shoot.
          (Are your binary variables coded 0 and 1?)
          The below example works.
          
          . 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)
          
            +--------------------------------------------+
            | factor               N_0   N_1   m_0   m_1 |
            |--------------------------------------------|
            | Price                 52    22     0     0 |
            | Price                 52    22     0     0 |
            |--------------------------------------------|
            | Weight (lbs.)         52    22     0     0 |
            |--------------------------------------------|
            | Repair record 1978    48    21     4     1 |
            |--------------------------------------------|
            | much_headroom         52    22     0     0 |
            +--------------------------------------------+
             N_ ... #records used below,   m_ ... #records not used
           
            +------------------------------------------------------------------------------------+
            |                              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 (×/geometric SD) or median (IQR) for continuous measures, and n (%) for categorical measures.

          Comment


          • #35
            Mark Chatfield Thank you very much. Is there a way to get statistics aggregated at the category level i.e. population the row dem_age?

            Code:
             +---------------------------------------------------------------------------------------------------------------------+
              |            Control       Medical Framing   Strengths Framing   Medical & Strengths Framing   Total          p-value |
              |---------------------------------------------------------------------------------------------------------------------|
              |            N=155         N=159             N=158               N=149                         N=621                  |
              |---------------------------------------------------------------------------------------------------------------------|
              | dem_age                                                                                                      0.83   |
              |    18-25   53 (34.19%)   47 (29.56%)       56 (35.44%)         48 (32.21%)                   204 (32.85%)           |
              |    26-35   51 (32.90%)   65 (40.88%)       62 (39.24%)         51 (34.23%)                   229 (36.88%)           |
              |    35-45   29 (18.71%)   30 (18.87%)       24 (15.19%)         28 (18.79%)                   111 (17.87%)           |
              |    46-55   12 (7.74%)    8 (5.03%)         6 (3.80%)           13 (8.72%)                    39 (6.28%)             |
              |    56-65   7 (4.52%)     8 (5.03%)         9 (5.70%)           8 (5.37%)                     32 (5.15%)             |
              |    66+     3 (1.94%)     1 (0.63%)         1 (0.63%)           1 (0.67%)                     6 (0.97%)              |
              +---------------------------------------------------------------------------------------------------------------------+
            Last edited by Bob Geldof; 02 Aug 2021, 15:05.

            Comment


            • #36
              Not entirely sure what you are asking. (You have two categorical variables.)
              What i can say is my command will do row (rather then column) percentages if you would like.

              Comment


              • #37
                Mark Chatfield yes so I'm looking to add the total number of observations and % in the dem_age x control group for example so populating the cells on dem_age row - if that makes sense?

                Comment


                • #38
                  The number 155 is given on the previous row. You'll have to manually add what 155 is as a % of 621. Be careful though, you will be mixing row and column percentages if you do this. Try emailing me if I have still not understood what you are wanting to do, giving me an example table to reproduce.

                  Comment


                  • #39
                    Thank you Mark!! This has blown my mind. I'm a bit sad about all the hours spent cutting and pasting I've been doing for years.....But very happy about all the hours I will save with table1_mc. Thank you!!

                    Comment


                    • #40
                      Mark,

                      Let me add my most sincere THANKS! for this awesome program. You absolutely nailed it for my particular needs. You eliminated one of my biggest annoyances with Table1_mc.

                      Cheers!

                      Comment


                      • #41
                        I just tried the above code but I don't get the n numbers FOR MY categorical variables...

                        Code:
                        table1_mc, by ($tretment) 
                        vars ( 
                        age contn %4.1f 
                        ethnicity cat %4.0f
                        surgical bin %4/0f 
                        )
                        nospace percent onecol missing total(before)

                        Comment


                        • #42
                          first, your post is incomplete as we have no idea what is in your global (#tretment)

                          second, your syntax is incorrect - see the help file and use they syntax it shows (which means using backward slashes between the variables in the "vars()" part of the command)

                          Comment


                          • #43
                            Hi Mark and Mark aficionados!

                            Let me first add my voice to the chorus of fans of table1_mc. What a great addition to Stata.

                            I would like to produce a table without percentages, just counts. Alternatively, a table that puts the percentages into another column, when exported to excel or similar, so that I can remove or modify it (Currently table1_mc puts the count and percentages in the same column, which makes it time consuming to edit for my current needs). I don't see any option to do this in the help file (though I may have missed it). I even tried "noperc" which is not in the help file, and got an odd result - not an error, but definitely not what I was expecting.

                            Is it possible to suppress the percentages?

                            Comment


                            • #44
                              Dear Mark,

                              Thank you for this wonderful program.

                              I had a question - is there any way to get three decimal places for the p-values even if p>0.1?

                              Thank you in advance,
                              Best,
                              Amay

                              Comment


                              • #45
                                Amay Banker ... not easily ... if you really want that level of precision, you could alter table1_mc.ado by replacing the two instances of "%4.2f" with "%5.3f"

                                Comment

                                Working...
                                X