Announcement

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

  • Problem with rank sum test

    Hello, I'm a new user of Stata. In my dataset variable compl_number in each row is the number of all complaints categorised by byte variables IDS, field and so on. When I use ranksum, I get the number of observations of byte variable, but not of variable compl_number. I guess the problem is in the dataset itself because the whole number of complaints is located in one cell in each row and Stata doesn't count it. What can I do in this situation?


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(IDS hosp field financ) int compl_number
    1 2 5 1  65
    1 1 0 1 320
    1 2 1 1  82
    1 2 1 2   9
    1 2 1 1   2
    1 2 3 1   0
    1 1 1 1 160
    1 1 5 1  87
    1 2 1 2  27
    1 2 2 1 100
    1 2 0 2  15
    1 1 1 1   0
    1 1 2 1  80
    1 1 0 2  30
    1 1 3 1 300
    1 1 1 2  50
    1 2 4 1   0
    1 1 5 2  26
    1 1 4 1   3
    1 1 1 2  10
    1 2 0 1  95
    1 2 5 2   6
    2 1 0 1 542
    2 2 5 1 312
    2 2 1 1  63
    2 1 3 1 600
    2 2 2 1 280
    2 1 2 2  20
    2 2 3 1   2
    2 2 3 2   3
    2 2 0 1 280
    2 1 1 1 452
    2 1 3 2 120
    2 1 5 1 273
    2 2 1 1 248
    2 1 2 1 200
    end
    label values IDS IDS
    label def IDS 1 "риск прописан", modify
    label def IDS 2 "не прописан", modify
    label values hosp hosp
    label def hosp 1 "adult", modify
    label def hosp 2 "child", modify
    label values field field
    label def field 0 "не_хир", modify
    label def field 1 "лор_стомат", modify
    label def field 2 "травма", modify
    label def field 3 "акуш", modify
    label def field 4 "универ", modify
    label def field 5 "хирургия", modify
    label values financ financ
    label def financ 1 "госуд", modify
    label def financ 2 "част", modify

    Code:
    . by hosp, sort : ranksum compl_number, by(IDS)
    
    --------------------------------------------------------------------------------------------------
    -> hosp = adult
    
    Two-sample Wilcoxon rank-sum (Mann-Whitney) test
    
             IDS |      obs    rank sum    expected
    -------------+---------------------------------
         риск п� |       11          81       104.5
         не про� |        7          90        66.5
    -------------+---------------------------------
        combined |       18         171         171
    
    --------------------------------------------------------------------------------------------------
    -> hosp = child
    
    Two-sample Wilcoxon rank-sum (Mann-Whitney) test
    
             IDS |      obs    rank sum    expected
    -------------+---------------------------------
         риск п� |       11        86.5       104.5
         не про� |        7        84.5        66.5
    -------------+---------------------------------
        combined |       18         171         171
    Last edited by Strekozova Sofia; 08 Nov 2024, 08:17.

  • #2
    Nothing is wrong with your dataset. And you are using -ranksum- correctly. You are just expecting it to output something that it isn't designed to output. It is not designed to output the total number of complaints. And I don't think anybody writing a program for the rank sum test would include that feature. That's because in general the variable being analyzed in the rank sum test is not a quantitative variable where it makes any sense to add up the totals. The typical application of rank sum is to an ordinal variable, where we can order the responses, but there is no meaningful magnitude associated with them.

    So to also output the total number of complaints in each group, you need to modify your code with some additional commands:
    Code:
    levelsof hosp, local(hospitals)
    foreach h of local hospitals {
        display _newline(2) `"-> hosp = `:label (hosp) `h''"'
        tabstat compl_number if hosp == `h', by(IDS) statistic(sum)
        ranksum compl_number if hosp == `h', by(IDS)
    }

    Comment


    • #3
      Thank you for explanation, Clyde!

      Comment

      Working...
      X