Announcement

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

  • See if one value in var2 is assigned to two or more values in var1

    Hi,

    I want to see if there is file number that has been used with two or more civil id at one hospital. Example data from excel as follows:

    CID File_number_int Hosp_code
    290120200145 12450 1
    320145005548 12450 1
    290120200145 3256 2
    280051600452 3256 3
    290120200145 5463 4
    29090121205 124888 5
    29090121205 124888 5

    I am not interested if same file number has been used by two civil id but in different hospital as this can happen normally. I am looking for same file number that has been used and assigned for different civil id at the same hospital code.

    Thanks for your help!

  • #2
    See https://www.stata.com/support/faqs/d...ions-in-group/ for a discussion of this question,

    Comment


    • #3
      I got this error and not sure what is wrong?

      Code:
      by Hospital_code_Num ( File_Number_int ), sort: gen diff = CID [1] != CID [_N]
      weights not allowed
      r(101);

      Comment


      • #4
        Code:
        by Hospital_code_Num ( File_Number_int ), sort: gen diff = CID [1] != CID [_N]
        
        // should be
        
        by Hospital_code_Num ( File_Number_int ), sort: gen diff = CID[1] != CID[_N]
        When square brackets are used to identify subscripts, as here, they must not be separated from the subscripted variable by whitespace.

        Comment


        • #5
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str12 CID float File_number_int int Hosp_code float(count_CID diff same)
          "290120200145"  12450 1 2 1 0
          "320145005548"  12450 1 2 1 0
          "290120200145"   3256 2 1 0 1
          "280051600452"   3256 3 1 0 1
          "290120200145"   5463 4 1 0 1
          "290901212055" 124888 5 2 0 1
          "290901212055" 124888 5 2 0 1
          end

          The results I got is this:
          CID File_number_int Hosp_code count_CID diff same
          290120200145 12450 1 2 1 0
          320145005548 12450 1 2 1 0
          290120200145 3256 2 1 0 1
          280051600452 3256 3 1 0 1
          290120200145 5463 4 1 0 1
          290901212055 124888 5 2 0 1
          290901212055 124888 5 2 0 1


          which is not right!

          Comment


          • #6
            Code:
            by File_number Hosp_code (CID), sort: gen byte problem = CID[1] != CID[_N]

            Comment


            • #7
              Thanks Clyde Schechter for this, it works now.

              Comment

              Working...
              X