New to this forum, so sorry for the wordy title.

I have 9 waves of individual level panel data on disability. Each observation includes a 9-digit string variable made up of 1's and 2's called 'trajectory' which records an individual's disability trajectory. For example, 111222111 would mean that they were not disabled in waves 1,2,3, they were disabled in waves 4,5,6 and not disabled in waves 7,8,9.

I wish to generate a new variable called 'chronicity' which records the length of disability. This variable would be equal to 0 if the individual is never disabled, 1 if they are disabled in a single period, 2 if they are disabled in 2 consecutive periods, 3 if they are disabled in 3 consecutive periods and so on.

The beginning of the code, where I denote the 'never-disabled' individuals is simple enough:

gen chronicity = .
replace chronicity = 0 if trajectory=="111111111"

However, when I wish to assign a 1 to denote the single-period disabled, I am struggling with the code. Here is an example of doing it wrong so that hopefully you can get the idea:

replace chronicity = 1 if trajectory=="111111112" | trajectory=="111111121" | trajectory=="111111211" | trajectory=="111112111" | trajectory=="111121111" | trajectory=="111211111" | "112111111" | trajectory=="121111111" | trajectory=="211111111"

Error: type mismatch

I've tried to use the inlist command too but this has been unsuccessful.

I'd be grateful for any help or ideas.

John