Hello everyone,

My original data is like this with two variables: "class" and "classlist". I am trying to search in "class" and get the values that fulfills "econ 10@" (@ can be any number from 1-9) and add the values in the variable of "classlist".
class classlist
econ 101 econ 511
econ 102 econ 10@
econ 221
econ 222
econ 303
So, my ideal result will look like this:
class classlist
econ 101 econ 511
econ 102 econ 10@
econ 221 econ 101
econ 222 econ 102
econ 303
My code is like this:
Code:
levelsof class if regexm(class,"^econ 10"+"[0-9|A-Z]$"),local(list)
foreach x of local list{
                                 tab classlist
                                 replace classlist = "`x'" in `r(N)'+1
                                  }
It is trying to do:
  1. use regular expression to find all the unique values in "class" that fulfill the format of "econ 10@"
  2. replace the (N+1)th observation of "classlist" with each of the unique values found above.
The problem is it keeps giving me the error code about the code fails to feed in the observation number through `r(N)'+1.
Code:
'2+1' invalid observation number
Any help would be appreciated.