Announcement

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

  • Getting percents in Stata 17 table command based sum of weights

    I'm working with a group of people who use SPSS. SPSS calculates row and column percents differently than Stata because it uses the rounded sum of weights instead of precise figure. I understand how to use the the sum of weights in the table command in Stata 17; however, row percents are not being calculated based on those rounded sum of weights seen in output. Instead they are calculated based on the precise weighted counts.

    It gives the row percent for the second level at 94% (12.787/13.579). I would like to see 93% which would be 13/14, based on the rounded sum of weights. Both R and SPSS give me the 92.8% figure, but I prefer to use Stata.
    Code:
    table (Q6) (Q2_3L)  [iw=weight] if surv_yr==2020, statistic(sumw)  statistic(percent, across(Q2_3L)) nformat(%9.0fc percent sumw)
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(Q6 Q2_3L)
    1 2
    1 .
    3 1
    . 1
    . 1
    3 1
    1 1
    1 1
    . .
    1 1
    1 1
    1 1
    1 1
    1 1
    1 3
    1 3
    3 3
    . 3
    1 2
    1 3
    1 3
    1 1
    . 3
    1 3
    3 2
    1 2
    1 3
    1 2
    . 3
    1 3
    . 3
    1 1
    1 3
    1 1
    1 3
    . 3
    1 3
    1 3
    end
    [/CODE]

    I'm assuming that this might be impossible, but I thought I would reach out to see if anyone has a workaround.
    Last edited by sladmin; 09 Nov 2021, 13:09. Reason: Image contained sensitive data.

  • #2
    Just a thought but you probably want to use -aweight- instead of -iweight- as the latter don't have a real definition (though since commands treat them equivalently). Second, you don't provide a weight variable in your example, but did you create a rounded weight, and use that with table? For example:

    Code:
    gen roundedwt = round(weight)

    Comment


    • #3

      Leonardo Guizzetti Sorry about that. You're right. I did not provide the weight variable. Newby mistake. I'll try to see if that works. Thanks.

      Comment


      • #4
        Originally posted by Leonardo Guizzetti View Post
        Just a thought but you probably want to use -aweight- instead of -iweight- as the latter don't have a real definition (though since commands treat them equivalently). Second, you don't provide a weight variable in your example, but did you create a rounded weight, and use that with table? For example:

        Code:
        gen roundedwt = round(weight)
        This worked perfectly. Thank you.

        Comment

        Working...
        X