Announcement

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

  • more than 2 groups found, only 2 allowed

    I have only 2 groups defined by "1" & "0", but I am getting the following error, when applying the Z test.

    error- more than 2 groups found, only 2 allowed

    command used for ztest : ztest arlocation, by(arlocation) sd1(117) sd2(18.42)

    any help would be much appreciated, thanks!

  • #2
    Check for missing values and other values

    Code:
    tab arlocation, missing

    Comment


    • #3
      Perhaps you also have missing values in the grouping variable?

      Also surely the variable you want to compare means of, cannot be the same as the variable that defines the groups?

      Code:
      ztest arlocation, by(arlocation) sd1(117) sd2(18.42)
      Edit: crossed with #2

      Comment


      • #4
        Originally posted by Hemanshu Kumar View Post
        Perhaps you also have missing values in the grouping variable?

        Also surely the variable you want to compare means of, cannot be the same as the variable that defines the groups?

        Code:
        ztest arlocation, by(arlocation) sd1(117) sd2(18.42)
        Edit: crossed with #2

        hey sorry it was a typo its "by(arlocationc)"

        and I do not have any missing value, I rechecked but I am still getting the same error

        Comment


        • #5
          Originally posted by Nick Cox View Post
          Check for missing values and other values

          Code:
          tab arlocation, missing
          Hi thanks for the reply, I do not have any missing value.

          Comment


          • #6
            hey guys thanks for helping me out. I just figured it out.
            instead of using numeric numbers, "1" & "0" for defining variables, I used the string variable now its working.

            Comment


            • #7
              Your by group must have 2 distinct values, or else you can use the -if- qualifier to restrict it to two categories. Missing values do not count towards the by-group levels and ar marked out of the estimation sample.

              Originally posted by Abdullah Akram View Post
              hey guys thanks for helping me out. I just figured it out.
              instead of using numeric numbers, "1" & "0" for defining variables, I used the string variable now its working.
              That should not have solved your problem, so I would be suspicious of your results.

              Here's a toy example showing these points

              Code:
              sysuse auto, clear
              
              // using if qualifier, we only select 2 levels of rep78 to use for the test.
              cap noi ztest price if inlist(rep78, 1, 3), by(rep78)
              
              cap noi ztest price, by(rep78) // gives error
              
              recode rep78 (1/2=1) (3/5=0), gen(rep2grp)
              tab rep2grp, mi
              ztest price, by(rep2grp) // no error
              
              gen rep2grp_string = string(rep2grp) if !mi(rep2grp)
              ztest price, by(rep2grp_string) // no error

              Comment

              Working...
              X