I have data from a trial where a patient answers a set of questions in the sequence q12, q14, q16 and q18. There can be upto 7 answers for the question. The restriction is that if a response appears in q12 then it cannot appear in q14-q18, and if answered in q14 it cannot appear in q16-q18 etc. Unfortunately some patients ignored this and there is repeated data.

Code:
* Example generated by -dataex-. To install: ssc install dataex

clear

input str171 q12m str155 q14m str171(q16m q18m)

`""g","a""'     `""e""'         `""g","a""'     `""g","c","a""'

`""g","c","a""' `""g","c","a""' `""g","c","a""' `""g","c","a""'

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","c""'     `""e""'         `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","b""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","c""'     `""g","a""'     `""g","a""'     `""g","a""'    

`""g","a""'     `""e""'         `""e""'         `""g","a""'    

`""g","a""'     `""e""'         `""g","a""'     `""g","a""'    

`""g","a""'     `""e""'         `""g","a""'     `""g","a""'    

`""g","a""'     `""e""'         `""g","a""'     `""g","a""'    

`""g","a""'     `""e""'         `""e""'         `""g","a""'    

`""g","a""'     `""e""'         `""e""'         `""g","a""'    

end
What I am attempting to do is to eliminate the repeated response such that line 1 would become:

Code:
  +-------------------------------------------------------+

     |        q12m          q14m          q16m          q18m |

     |-------------------------------------------------------|

  1. |     "g","a"           "e"       " "," "   " ","c"," " |

I thought that I might be able to achieve this with inlist:

Code:
replace q14m = "" if inlist(q14m,q12m)
replace q16m = "" if inlist(q16m,q12m)
replace q18m = "" if inlist(q18m,q12m)
but this only matches exact cases.
Code:
-----------------------------------------------+

     |        q12m      q14m      q16m          q18m |

     |-----------------------------------------------|

  1. |     "g","a"       "e"             "g","c","a" |

  2. | "g","c","a"                                   |
I would be grateful for some advice on how to solve this problem.

Martyn