Announcement

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

  • Number of observations - summary table - STATA 18 - dtable

    Hello Everyone!
    I would like to create a summary table with the number of observations for each variables.

    code :
    dtable age bmi sbp dbp heart_rate total_cholesterol
    Summary
    N 1,066
    Age 56.658 (16.130)
    BMI 27.542 (6.058)
    sbp 133.361 (20.200)
    dpb 78.464 (12.601)
    HR 77.082 (13.093)
    I would like to have a column N for each variables (Age, BMI, sbp etc.)

    Thank you for your help,

  • #2
    There is probably a way to do this with -dtable-, and maybe somebody will show that. But in this case, it is probably easier to use -table-. I illustrate the approach using the online nhanes2.dta:
    Code:
    clear*
    webuse nhanes2
    
    local for_table age bpsystol bpdiast
    
    table (var), statistic(count `for_table') ///
        statistic(mean `for_table') statistic(sd `for_table') ///
        nformat(%4.3f mean sd) sformat("(%s)" sd) style(Table-1)

    Comment


    • #3
      Add the option continuous(, statistics(count mean sd)) to your call to dtable to add the sample size (number of nonmissing values) for each variable.

      Here is this option in action using the example setup by Clyde.
      Code:
      dtable age bpsystol bpdiast, ///
              continuous(, statistics(count mean sd))
      Here is the resulting table
      Code:
      . dtable age bpsystol bpdiast, ///
      >         continuous(, statistics(count mean sd))
      
      ------------------------------------------------
                                       Summary        
      ------------------------------------------------
      N                                         10,351
      Age (years)               10,351 47.580 (17.215)
      Systolic blood pressure  10,351 130.882 (23.333)
      Diastolic blood pressure  10,351 81.715 (12.927)
      ------------------------------------------------
      If you build this kind of table often, you can save your dtable style changes to a file in your PERSONAL directory and set it as the default. For further details, see the section titled "Save your style choices for next time" in the Remarks and examples of [R] dtable.

      Comment


      • #4
        It works, Thank you very much for your help!

        Comment

        Working...
        X