Announcement

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

  • Creating Tables with results on one row

    Hello: I'm not sure this is going to be picked up on an old thread that had no replies, so I would like to re-address if able?

    https://www.statalist.org/forums/for...oc#post1539751

    I am hoping someone has this answer perhaps? I too am trying to figure out creating simple tables where the frequency and percentage appear in one row for each category. I cannot find how to do this as the table command seems to only allow the percentages and frequencies to be on different rows?

    For example using the example table presented, I would like to create a table in similar formatting that says:

    single married total
    white 487 (60.57%) 1150 (79.75%) 1637


    Instead of the original:
    singe married total
    white (frequency) 487 1150 1637
    white (percent) 60.57 79.75

    Please advise and thanks!

  • #2
    Code:
    ssc install estout, replace
    Code:
    sysuse nlsw88, clear
    estpost tab race married
    esttab, aux(colpct) wide keep(white) unstack nonumb mlab(none) compress nonotes
    Res.:

    Code:
    . esttab, aux(colpct) wide keep(white) unstack nonumb mlab(none) compress nonotes
    
    -------------------------------------------------------------------------------
                  single                married                  Total             
    -------------------------------------------------------------------------------
    white            487      (60.57)      1150      (79.75)      1637      (72.89)
    -------------------------------------------------------------------------------
    N               2246                                                           
    -------------------------------------------------------------------------------
    Last edited by Andrew Musau; 24 Aug 2022, 11:50.

    Comment


    • #3
      Thank you!!

      Andrew Musau,
      I do wonder--without needing to use this additional package, are the inherent table/tab features in Stata unable to perform this sort of customization of layout?

      Thanks again for help.

      Comment


      • #4
        yes, internal commands can be used; you might want to start with Chuck Huber's 7-part blog intro; here is a link to the first of the seven: https://blog.stata.com/2021/06/07/cu...table-command/

        Comment


        • #5
          Thank you both and I will review the materials.

          I do have a follow up question regarding tables.
          This may involve the -command- option embedded within the table feature, but I do not know how to use properly. Examples I've seen only describe adding regressions using this feature. Or perhaps there is a different way to approach:

          How does one take data populated from a table and apply an operation to it?
          Say I have a table that I generated using command
          Code:
          table (widget) (broken_status)
          Cost by Widget Broken (1) Not Broken (0) Total Annual Cost
          W1 200.00 800.00 1000.00
          W2 1000.00 1000.00 2000.00
          W3 300.00 200.00 500.00
          W4 50.00 50.00 100.0

          How could I apply simple arithmetic to the OUTPUT of the table rather then have to go to the original data set to create an additional table column that shows "cost per month of broken widgets", which would == broken/12:

          Cost by Widget Broken (1) Not Broken (0) Total Annual Cost Monthly Broken Cost
          W1 200.00 800.00 1000.00 16.666
          W2 1000.00 1000.00 2000.00 83.333
          W3 300.00 200.00 500.00 25
          W4 50.00 50.00 100.0 4.166

          Please advise and thanks again!


          Comment


          • #6
            Post #5 was subsequently reposted as a new topic, with subsequent replies, at

            https://www.statalist.org/forums/for...ns-or-commands

            Comment

            Working...
            X