Announcement

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

  • more than 2 groups found, only 2 allowed r(499)

    Hello,

    I'm trying to run a mann whitney u test to compare the medians between cfrnonLAD and cfrLAD
    Click image for larger version

Name:	Screenshot 2024-05-12 224651.png
Views:	1
Size:	106.3 KB
ID:	1753111


    but I keep getting this error message:
    . ranksum cfrnonlad, by(cfrlad) porder exact
    more than 2 groups found, only 2 allowed
    r(499);

    any idea how to fix this? I'm a complete newbie to stata.

    Thanks!

  • #2
    Originally posted by Nida Latif View Post
    . . . any idea how to fix this?
    You could try something like the following.
    Code:
    rename cf*LAD lad#, addnumber(0)
    generate long row = _n
    reshape long lad, i(row) j(grp)
    ranksum lad, by(grp)

    Comment


    • #3
      You can use stack as an alternative.
      Code:
      stack cfrnonLAD cfrLAD, into(lad)
      median lad, by(_stack)

      Comment


      • #4
        Thank you, it worked when I used the code:
        rename cf*LAD lad#, addnumber(0) generate long row = _n reshape long lad, i(row) j(grp) ranksum lad, by(grp) However, when I used the following code:

        stack cfrnonLAD cfrLAD, into(lad)
        median lad, by(_stack)

        It gave me the results of pearson's chi square instead of mann whitney u test.

        Comment


        • #5
          Originally posted by Nida Latif View Post
          median lad, by(_stack)

          . . . instead of mann whitney u test.
          Yes. In your original post you said that your objective is "to compare the medians", and the Mann-Whitney U test isn't strictly a test of the equality of medians.

          Comment


          • #6
            Thank you. This is really helpful!

            Comment


            • #7
              Originally posted by Nida Latif View Post
              Thank you.
              You're welcome. Thank you for closing out the thread.

              Comment


              • #8
                Always plot the data too. Even with two groups, the difference can be much more complicated than just a shift, as shown by a difference in medians.

                https://www.statalist.org/forums/for...oup-histograms gives examples of side-by-side comparison focused on medians and quartiles AND means AND indeed all the detail in distributions.

                Comment


                • #9
                  Hello,

                  I tried the same code to run the mann whitney u test to compare the median of baselinelessthan50 and baseline greaterthan50

                  rename baselin*greaterthan50 greaterthan50#, addnumber(0)
                  generate long row = _n
                  reshape long greaterthan50, i(row) j(grp)
                  ranksum greaterthan50, by(grp)

                  Click image for larger version

Name:	Screenshot 2024-05-19 143254.png
Views:	1
Size:	136.3 KB
ID:	1753822


                  but its giving me the following error:

                  Click image for larger version

Name:	Screenshot 2024-05-19 143226.png
Views:	1
Size:	19.9 KB
ID:	1753823

                  any idea how to fix this?

                  Comment


                  • #10
                    Your reshape just left the dataset in the same shape with different variable names. It would be easier to help if you gave us a data example of the original data (not a screenshot).

                    Please read and act on

                    https://www.statalist.org/forums/help#stata

                    and follow up with

                    Code:
                    dataex, count(160)

                    Comment


                    • #11
                      Originally posted by Nida Latif View Post
                      I tried . . . the mann whitney u test to . . . baselinelessthan50 and baseline greaterthan50
                      . . . any idea how to fix this?
                      It'll probably be more straightforward to use stack for this.
                      Code:
                      stack *than50, into(outcome) clear
                      tabulate _stack
                      assert r(r) ==  2
                      ranksum outcome, by(_stack)

                      Comment


                      • #12
                        Thank you so much Nick and Joseph for all your help. I really appreciate it! It worked when I used stack like Joseph suggested.

                        Comment

                        Working...
                        X