Dear Statalist,

I am trying to fill missing values between two markers (start marker and end marker).

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte epoch str8 activity
 1 ""        
 2 ""        
 3 "sleep"   
 4 ""        
 5 ""        
 6 ""        
 7 "sleep"   
 8 ""        
 9 "work"    
10 ""        
11 ""        
12 ""        
13 ""        
14 ""        
15 "work"    
16 ""        
17 "exercise"
18 ""        
19 "exercise"
20 ""        
end
"sleep", "work", and "exercise" are the markers. In between two markers with the same name, I want to fill the missing values with the name of the marker.

So I want to get to this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte epoch str8 activity
 1 ""        
 2 ""        
 3 "sleep"   
 4 "sleep"   
 5 "sleep"   
 6 "sleep"   
 7 "sleep"   
 8 ""        
 9 "work"    
10 "work"    
11 "work"    
12 "work"    
13 "work"    
14 "work"    
15 "work"    
16 ""        
17 "exercise"
18 "exercise"
19 "exercise"
20 ""        
end
I cannot use fill down because this will ignore the end marker:

This:
Code:
replace activity=activity[_n-1] if activity=="" // fill down
Will result in this:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte epoch str8 activity
 1 ""        
 2 ""        
 3 "sleep"   
 4 "sleep"   
 5 "sleep"   
 6 "sleep"   
 7 "sleep"   
 8 "sleep"   
 9 "work"    
10 "work"    
11 "work"    
12 "work"    
13 "work"    
14 "work"    
15 "work"    
16 "work"    
17 "exercise"
18 "exercise"
19 "exercise"
20 "exercise"
end
Note that the actual data has 14425 observations. How can I get to the second example from the first example?

I am looking forward to your solutions.

Thanks so much.

Best regards,

Rob