Announcement

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

  • Record IDs have trailing characters, how to remove?

    Hello,
    I am working on a dataset that has multiple record IDs with suffixes (RecordID x2, x3, x4, etc) to denote which instance of procedure the observation is denoting. I want to drop the x2, x3, x4, etc off the end of the record IDs so that I will have duplicate IDs. (I'm planning to cluster by ID later on in my analysis) .
    I'm not sure how to get rid of the trailing bits after my record numbers. Can anyone help with this?
    Thanks!

  • #2
    Marina:
    welcome to this forum.
    Do you mean something along the following lines?
    Code:
    . set obs 1
    Number of observations (_N) was 0, now 1.
    
    . g Alfa="RecordID x2"
    
    . split Alfa , p("")
    variables created as string: 
    Alfa1  Alfa2
    
    . list
    
         +--------------------------------+
         |        Alfa      Alfa1   Alfa2 |
         |--------------------------------|
      1. | RecordID x2   RecordID      x2 |
         +--------------------------------+
    
    . drop Alfa Alfa2
    
    . list
    
         +----------+
         |    Alfa1 |
         |----------|
      1. | RecordID |
         +----------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Perfect! Thanks so much for your help!

      Comment

      Working...
      X