Dear all,
sorry for the apparently silly question.

I am trying to write a syntax that loops up to when the condition specified it is not anymore present.

Basically, the command is:
Code:
drop if status!=2 & status[_n-1]==2 & caso==caso[_n-1]
I want to loop this command in all the waves, but the following command does not work:
Code:
forval i in 1 (1) 18 {
 drop if status!=2 & status[_n-1]==2 & caso==caso[_n-1] if wave == `i'
 }
*
Do you have any advise? Here the fictious data I am using:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(caso status wave)
1 1  1
1 1  2
1 2  3
1 .  4
1 2  5
1 1  6
1 .  7
1 .  8
1 2  9
1 2 10
1 . 11
1 1 12
1 2 13
1 2 14
1 1 15
1 . 16
1 1 17
1 1 18
2 .  1
2 2  2
2 1  3
2 1  4
2 2  5
2 .  6
2 .  7
2 2  8
2 2  9
2 3 10
2 2 11
2 . 12
2 1 13
2 . 14
2 . 15
2 2 16
2 1 17
2 3 18
end
Thanks a lot, best, G