SAMPLE DATA:
Code:
input person var1
1 1
1 2
1 .
1 3
1 1
1 4
2 2
2 2
2 .
2 .
2 3
2 3
3 3
3 4
3 .
3 .
3 .
3 .
end
Rules for var1:

if var1 is missing, fill with previous value
if var1 at time t is 3, all future var1 values are set to 3 unless there is a 4, which stays a 4
if var1 is missing after a 4, remove that row

DESIRED OUTPUT:

Code:
input person var1
id var1
1 1
1 2
1 2
1 3
1 3
1 4
2 2
2 2
2 2
2 2
2 3
2 3
3 3
3 4
end