Announcement

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

  • P-value: Stored Results of Ranksum

    Hi,

    I was wondering if there is a way to obtain the p-value from stored results of ranksum tests. Below are the options I found through "help ranksum", none of which match.
    Any other options showing correlation between a categorical and continuous variable would also work!

    Stored results

    ranksum stores the following in r():

    Scalars
    r(N_1) sample size n_1
    r(N_2) sample size n_2
    r(z) z statistic
    r(Var_a) adjusted variance
    r(group1) value of variable for first group
    r(sum_obs) actual sum of ranks for first group
    r(sum_exp) expected sum of ranks for first group
    r(porder) probability that draw from first population is larger than
    draw from second population
    Thank you!
    Priscilla

  • #2
    Priscilla:
    you may want to consider:
    Code:
    .  webuse fuel2
    
    . ranksum mpg, by(treat)
    
    Two-sample Wilcoxon rank-sum (Mann–Whitney) test
    
           treat |      Obs    Rank sum    Expected
    -------------+---------------------------------
       Untreated |       12         128         150
         Treated |       12         172         150
    -------------+---------------------------------
        Combined |       24         300         300
    
    Unadjusted variance      300.00
    Adjustment for ties       -4.04
                         ----------
    Adjusted variance        295.96
    
    H0: mpg(treat==Untreated) = mpg(treat==Treated)
             z = -1.279
    Prob > |z| = 0.2010
    Exact prob = 0.2117
    
    . return list
    
    scalars:
                      r(N) =  24
                    r(N_1) =  12
                    r(N_2) =  12
                 r(group1) =  0
                r(sum_obs) =  128
                r(sum_exp) =  150
                  r(Var_a) =  295.9565217391304
                      r(z) =  -1.278817949868369
                      r(p) =  .2009611714248259
                    r(p_l) =  .1004805857124129
                    r(p_u) =  .8995194142875871
                r(p_exact) =  .211683793390618
              r(p_l_exact) =  .105841896695309
              r(p_u_exact) =  .9006281442342823
    
    . g wanted=r(p_exact)
    
    . list in 1/10
    
         +----------------------------+
         | mpg       treat     wanted |
         |----------------------------|
      1. |  20   Untreated   .2116838 |
      2. |  23   Untreated   .2116838 |
      3. |  21   Untreated   .2116838 |
      4. |  25   Untreated   .2116838 |
      5. |  18   Untreated   .2116838 |
         |----------------------------|
      6. |  17   Untreated   .2116838 |
      7. |  18   Untreated   .2116838 |
      8. |  24   Untreated   .2116838 |
      9. |  20   Untreated   .2116838 |
     10. |  24   Untreated   .2116838 |
         +----------------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi,

      Thank you so much for the response Carlo!

      Unfortunately, I am using Stata 15, so only the options below are shown for me when I use "ranksum" followed by "return list"

      Ho: age_a~rt(ncigr3..==0) = age_a~rt(ncigr3..==1)
      z = 1.870
      Prob > |z| = 0.0615

      . return list

      scalars:
      r(N_2) = 19
      r(N_1) = 91
      r(Var_a) = 15993.25
      r(z) = 1.870091180546235
      r(sum_exp) = 5050.5
      r(sum_obs) = 5287
      r(group1) = 0
      However, I found Nick's archived post (http://www.stata.com/statalist/archi.../msg00622.html) and the below code seems to work

      ranksum age_atchemostart if cond1!=.& cond2!=. & ncigr3var!=., by (ncigr3var)
      scalar pvalue = 2*normprob(-abs(`r(z)'))
      display pvalue // to check that it matches
      putexcel D6 = pvalue, nformat(number_d3)
      Thanks again!
      Priscilla

      Comment


      • #4
        Priscilla:
        happy with reading that you found a solution.
        In your future posts, please mention the Stata release that you're using (as per FAQ). Otherwise, interested listers assume that you are worworking with Stata 18 and reply accordinglyl (and unhelpfully, if your Stata release is older than the last one).Thanks.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X