Dear all,

I would like to ask how to fill in empty adjacent rows within a group. Problem here is the confusing data structure.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str12 subjid str21 personid str23 invtype
"a" "1" "Cranial Ultrasound Scan"
""  "1" "Other Ultrasound Scan"  
""  "1" "CT scan"                
""  "1" "X-ray"                  
""  "1" "EEG"                    
""  "1" "MRI"                    
""  "1" "ECHO"                   
""  "1" "ECG"                    
""  "1" ""                       
""  "1" ""                       
""  "1" ""                       
"b" "2" "Cranial Ultrasound Scan"
""  "2" "Other Ultrasound Scan"  
""  "2" "CT scan"                
""  "2" "X-ray"                  
""  "2" "EEG"                    
""  "2" "MRI"                    
""  "2" "ECHO"                   
""  "2" "ECG"                    
""  "2" ""                       
""  "2" ""                       
end

I want to put subjid like this.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str12 subjid str21 personid str23 invtype
"a" "1" "Cranial Ultrasound Scan"
"a" "1" "Other Ultrasound Scan"  
"a" "1" "CT scan"                
"a" "1" "X-ray"                  
"a" "1" "EEG"                    
"a" "1" "MRI"                    
"a" "1" "ECHO"                   
"a" "1" "ECG"                    
""  "1" ""                       
""  "1" ""                       
""  "1" ""                       
"b" "2" "Cranial Ultrasound Scan"
"b" "2" "Other Ultrasound Scan"  
"b" "2" "CT scan"                
"b" "2" "X-ray"                  
"b" "2" "EEG"                    
"b" "2" "MRI"                    
"b" "2" "ECHO"                   
"b" "2" "ECG"                    
""  "2" ""                       
""  "2" ""                       
end
Using personid is not a good idea because personid is repeated in row 4651 again- it strats with 1, 2 ...

if you let me know any solution for this, I would reapply appreciate it.

Kind regards,

Kim