Announcement

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

  • Remove prefix in ID variable individual row names

    I want to rename the individual rows in one column which represents the ID variable for each individual entity that has been tracked over four years of the dataset. I am constructing a panel and currently the ID includes 'ETyear' as the prefix to each variable. Thus, the panel is not recognising 'ET200000001' as the same entity as 'ET200500001'. Even though it identifies the same entity in reality. So each of these rows in this column with the IDs has a yearly prefix, but the ending matches the group it should be belonging to.

    Is there a way to remove this prefix from the entire column, I would be trying to remove the prefix for the four years separately -i.e. ET2000, ET2005, ET2011, ET2016. I have 2311 individual rows currently so it would be impossible to do manually.

    I'm also thinking I could potentially do this in excel but wanted to check to see if anyone knows of a fix for stata first...


  • #2
    Nancy-Jane:
    welcome to this forum.
    Assuming that ID is in -string- format, you may want to do something along the following lines:
    Code:
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . g A="ET200000001"
    
    . g B=substr(A,-6,6)
    
    . list
    
         +----------------------+
         |           A        B |
         |----------------------|
      1. | ET200000001   000001 |
         +----------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you so much - I tried a variation of that and it worked perfectly!

      Comment

      Working...
      X