Announcement

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

  • Combining unweighted frequencies and weighted percentages in dtable under svy

    I have a question regarding apply the dtabe command to data with complex weight.

    Here is some sample codes:
    Code:
    webuse nhanes2, clear
    
    svyset [pweight=finalwgt], psu(psu) strata(strata)
    
    * Without survey weight:
    dtable bmi i.race, by(sex)
    
    * With survey weight:
    dtable bmi i.race, by(sex) svy
    And the results are:

    Code:
    . * Without survey weight:
    . dtable bmi i.race, by(sex)
    
    -------------------------------------------------------------------
                                               Sex                    
                               Male          Female          Total    
    -------------------------------------------------------------------
    N                      4,915 (47.5%)  5,436 (52.5%) 10,351 (100.0%)
    Body mass index (BMI) 25.510 (4.024) 25.563 (5.600)  25.538 (4.915)
    Race                                                              
      White                4,312 (87.7%)  4,753 (87.4%)   9,065 (87.6%)
      Black                  500 (10.2%)    586 (10.8%)   1,086 (10.5%)
      Other                   103 (2.1%)      97 (1.8%)      200 (1.9%)
    -------------------------------------------------------------------
    
    .
    . * With survey weight:
    . dtable bmi i.race, by(sex) svy
    
    --------------------------------------------------------------------------------
                                                      Sex                          
                                 Male              Female               Total      
    --------------------------------------------------------------------------------
    N                     56,159,480 (47.9%) 60,998,033 (52.1%) 117,157,513 (100.0%)
    Body mass index (BMI)     25.480 (3.956)     25.087 (5.462)       25.276 (4.803)
    Race                                                                            
      White               49,504,800 (88.2%) 53,494,749 (87.7%)  102,999,549 (87.9%)
      Black                 5,096,044 (9.1%)  6,093,192 (10.0%)    11,189,236 (9.6%)
      Other                 1,558,636 (2.8%)   1,410,092 (2.3%)     2,968,728 (2.5%)
    --------------------------------------------------------------------------------
    My question: In public health literature, the convention is to report every weighted item, expect the frequencies which are often either omitted or reported unweighted. Is there a way I can achieve that with code instead of manual replacement?

    This is my "wanted" table:

    Code:
    -------------------------------------------------------------------
                                               Sex                    
                               Male          Female          Total    
    -------------------------------------------------------------------
    N                      4,915 (47.9%)  5,436 (52.1%) 10,351 (100.0%)
    Body mass index (BMI) 25.480 (3.956) 25.087 (5.462) 25.276 (4.803)
    Race                                                              
      White                4,312 (88.2%)  4,753 (87.7%)   9,065 (87.9%)
      Black                  500  (9.1%)    586 (10.0%)   1,086  (9.6%)
      Other                   103 (2.8%)      97 (2.3%)      200 (2.5%)
    -------------------------------------------------------------------
    Many thanks!

    EDIT: After some digging, I was able to create something with Race:

    Code:
    dtable bmi, factor(i.race, stat(fvrawfreq fvpercent)) by(sex) svy
    which gives:

    Code:
    --------------------------------------------------------------------------------
                                                      Sex                           
                                 Male              Female               Total       
    --------------------------------------------------------------------------------
    N                     56,159,480 (47.9%) 60,998,033 (52.1%) 117,157,513 (100.0%)
    Body mass index (BMI)     25.480 (3.956)     25.087 (5.462)       25.276 (4.803)
    Race                                                                            
      White                    4,312 (88.2%)      4,753 (87.7%)        9,065 (87.9%)
      Black                       500 (9.1%)        586 (10.0%)         1,086 (9.6%)
      Other                       103 (2.8%)          97 (2.3%)           200 (2.5%)
    --------------------------------------------------------------------------------
    However, the numbers in the sample size (N) row remains elusive. Would appreciate any tips.

    EDIT: Woah!! My 1000th post!!
    Last edited by Ken Chui; 27 Nov 2023, 10:06.

  • #2
    Alright... I ended up solving my own problem. Here is the code:

    Code:
    dtable bmi, factor(i.race, stat(fvrawfreq fvpercent)) sample(, statistics(freq percent)) by(sex) svy
    And we'll get:

    Code:
    -------------------------------------------------------------------
                                               Sex                     
                               Male          Female          Total     
    -------------------------------------------------------------------
    N                      4,915 (47.9%)  5,436 (52.1%) 10,351 (100.0%)
    Body mass index (BMI) 25.480 (3.956) 25.087 (5.462)  25.276 (4.803)
    Race                                                               
      White                4,312 (88.2%)  4,753 (87.7%)   9,065 (87.9%)
      Black                   500 (9.1%)    586 (10.0%)    1,086 (9.6%)
      Other                   103 (2.8%)      97 (2.3%)      200 (2.5%)
    -------------------------------------------------------------------
    Last edited by Ken Chui; 27 Nov 2023, 10:14.

    Comment


    • #3
      This is the way.

      Comment

      Working...
      X