Dear Statalist,
I am trying to determine whether elements in a variable is in local list. I have two dataset. The first data set will be stored as a local list. Then, I want to see if the elements from the second dataset is in local list.
Below is my approach:
Error message of "_"A_1 invalid name". I don't understand what is the problem here.
Thanks!
I am trying to determine whether elements in a variable is in local list. I have two dataset. The first data set will be stored as a local list. Then, I want to see if the elements from the second dataset is in local list.
Below is my approach:
Code:
/* read in the first data set */ clear input str22 Name "A_1" "A_2" "A_3" "B_1" "B_2" "B_3" end /* save as local list */ levelsof Name, local(varlist) di "`varlist'" /* read in the second data set */ clear input str22 NameCheck "A_1" "A_3" "A_6" "A_4" "B_2" "B_4" end /* check whether element is in local list */ gen byte var2_inlist = 0 foreach m of local `varlist' { replace var2_inlist = 1 if !var2_inlist & (NameCheck == `m') }
Thanks!
Comment