Announcement

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

  • Help needed

    Hi, thank you in advanced for helping me, I'm doing an internship and i'm really struggling with STATA cause i've never worked with it. So i've cleaned my data (I had 3 datasets and i've append them) but now I want to create groups for triplets (so there is a case and two controls) and I want to analyse within the groups of triplets. They all have the same number but not the same letters so im guessing with strings but i really don't know. Example : EX-E1 , EX-HHC1 et EX-VC1 are together. Can someone help me? Thank you so much

  • #2
    Originally posted by Mari-Ali Pri View Post
    They all have the same number but not the same letters
    Do the numbers always appear at the end of the string? If not, present a data example using the dataex command (see FAQ Advice #12 for details).

    Code:
    clear
    input str10 ID
    "EX-E1"  
    "RK-32"
    "EX-HHC1" 
    "EX-VC1"
    "ML13"
    "V6"
    "TPP13"
    "MX32"
    end
    
    gen group= ustrregexra(ID, "(.*)[^\d]([\d]+$)", "$2")
    Res.:

    Code:
    . sort group
    
    . l, sepby(group)
    
         +-----------------+
         |      ID   group |
         |-----------------|
      1. |  EX-VC1       1 |
      2. |   EX-E1       1 |
      3. | EX-HHC1       1 |
         |-----------------|
      4. |   TPP13      13 |
      5. |    ML13      13 |
         |-----------------|
      6. |   RK-32      32 |
      7. |    MX32      32 |
         |-----------------|
      8. |      V6       6 |
         +-----------------+

    Comment


    • #3
      Hi, yes the numbers are always at the end. So i'm not sure if I can use the code you sent. This is a real example of my data.
      AUDEM-E1
      AUDEM-VC1
      AUDEM-HHC1
      AUDEMHHC-2
      AUDEM-VC2
      AUDEM-E2
      ETC, ETC
      I want all the 1 together so it makes a triplet. Thanks!
      Attached Files

      Comment


      • #4
        Mari-Ali Pri : Welcome to the Stata Forum!

        You have been asked to read the FAQ Advice #12 and to present a data example using the dataex command -- please do so (I would even recommend to read the complete FAQ = advice on posting to Statalist). There you will also see that (for good reasons) you are advised not to post attachments (see FAQ Advice #12.5).

        Comment

        Working...
        X