Announcement

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

  • Creating own table in Stata

    Hi,

    Slightly strange request but I am doing some analysis and tabulations for one of my colleagues to help out and to give the results back to her I am just saving everything to the log file. One of the tables I want to show her manipulates the numbers in an awkward way that i think would take me a long time to figure out (and to explain here) so i was wondering if it is possible to write code so that a table i have designed will display in the log file?

    This table would have the form of a basic tabulation so something like this;

    Code:
               | Condition             |
    Years      | 0           1         | Proportion
    -----------+-----------------------+----------------
    Missing    | 0          11         |
    0-4        | 145        13         | 0.09
    5-9        | 130        15         | 0.12
    10-19      | 115        15         | 0.13
    20-29      | 101        14         | 0.14
    30-39      |  96         5         | 0.05
    40-50      |  96         0         | 0.00
    -----------+-----------------------+-----------------
    Thanks
    Cydney
    Last edited by Cydney Bruce; 22 May 2019, 08:50.

  • #2
    I'm not sure I understand; the result shown in your final column appears to be the frequency in the "1" column divided by the frequency in the "0" column; is that what you want? if so, try -tabulate- with the summarize option (the numbers will be in different place but will be there); see
    Code:
    help tabulate_summarize

    Comment


    • #3
      Hi Rich thank you for responding

      That is exactly what those numbers are, but the 0 and 1 column aren't the numbers that I've gotten from the Stata command before, so without dropping all of my data to create a new data set with those value in to tabulate i don't know a natural way to get to this table.

      I think i may have answered my own question though so i will post what i have done here and if anyone can find a better way to do it please let me know!

      Code:
      program tab
          di "{col 10}|" _skip(2) "Thyroid Condition" _skip(3) "|" "{col 10}"
          di "{col 4}Years" _skip(1) "|" _skip(7) "No" _skip(1) "|"_skip(7) "Yes" _skip(1)"|" _skip(1)"Proportion" 
          di "{hline 45}"
          di "{col 2}Missing" _skip(1) "|" _skip(10) "|" _skip(8) "11" _skip(1) "|"
          di "{col 6}0-4" _skip(1) "|" _skip(6) "145" _skip(1) "|" _skip(8) "13" _skip(1) "|" _skip(3) "0.090"
      end    
       
      tab
      which creates the following output:
      Code:
               |  Thyroid Condition   |
         Years |       No |       Yes | Proportion
      ---------------------------------------------
       Missing |          |        11 |
           0-4 |      145 |        13 |   0.090

      Comment

      Working...
      X