Announcement

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

  • Specific Table with frequency and percentages

    I need to create a table like this, with the same variables as the photo, what command I can run in Stata 17 (I suppose that is table, but I don't get how to set the percentages of BMI>30). Thanks and sorry for photo.


    Click image for larger version

Name:	4e232ed3-b510-4300-b43e-ade3aef63524.jpg
Views:	1
Size:	1.00 MB
ID:	1736782

  • #2
    Here is an example using some survey data, but not using any of the
    survey characteristics (weights, PSU, strata, ...).

    Code:
    webuse nhanes2l
    
    * list of categorical variables
    unab vlist : agegrp sex hlthstat heartatk rural agegrp
    
    * compute statistics of interest and with suggested layout
    table (var) (diabetes[1] result), ///
        stat(fvfrequency `vlist') ///
        stat(fvpercent `vlist') ///
        nototal
    
    * change some result labels
    collect label levels result ///
        fvfrequency "n" ///
        fvpercent "% Diabetic" ///
        , modify
    * change the row header style
    collect style row stack, nobinder
    * hide the -diabetes- header labels; we already have it the label for
    * result[fvpercent]
    collect style header diabetes, title(hide) level(hide)
    * change numeric format for factor variable percent
    collect style cell result[fvpercent], nformat(%6.1f)
    
    * replay table
    collect preview
    Here is the resulting table.
    Code:
    --------------------------------------
                       |    n   % Diabetic
    -------------------+------------------
    Age group          |
      20–29            |   15          3.0
      30–39            |   21          4.2
      40–49            |   42          8.4
      50–59            |   72         14.4
      60–69            |  238         47.7
      70+              |  111         22.2
    Sex                |
      Male             |  217         43.5
      Female           |  282         56.5
    Health status      |
      Excellent        |   24          4.8
      Very good        |   45          9.0
      Good             |  133         26.7
      Fair             |  162         32.5
      Poor             |  135         27.1
    Prior heart attack |
      No heart attack  |  435         87.2
      Had heart attack |   64         12.8
    Rural              |
      Urban            |  314         62.9
      Rural            |  185         37.1
    --------------------------------------

    Comment


    • #3
      Thank you very much for your reply. I have a similar problem. I thought I saw in the manual functions like "fvrowpercent", I thought the function was a bit similar. So what is it for?

      Comment


      • #4
        Thanks Jeff!!!

        Comment


        • #5
          Thank you, this is exactly what I'm looking for! Unfortunately I only have Stata 16.1, so keep getting blocked by errors/invalids, is it possible to do similar? I've tried to amend myself but I'm still pretty new to Stata..

          Thank you in advance,
          Lisa

          Comment

          Working...
          X