I want to replace the missing observations in HSCode variable with the previous HScode. I use the following code.

Code:
split HSCode, parse(:)
replace HSCode1 = HSCode1[_n-1] if HSCode1 == " "

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str102 HSCode str32 Country double USD
"01069000: OTHER LIVE ANIMALS, NES"                                               ""                              324.08
""                                                                                "US: United States"             324.08
"02109990: MEAT AND EDIBLE MEAT OFFAL,SALTED,IN BRINE,DRIED OR SMOKED,OTHER, Nes" ""                             4786.91
""                                                                                "MM: Myanmar"                  4786.91
"03019290: Live Eels, Excl. Fry"                                                  ""                          1364530.58
""                                                                                "CN: China"                 1346777.33
""                                                                                "HK: Hong Kong"                 6915.4
""                                                                                "US: United States"           10837.86
"03027990: Other than Eels, EXCL. Wrapped/canned upto 2.5 Kg"                     ""                          1023937.48
""                                                                                "IN: INDIA"                 1023937.48
"03028999: Other than Hilsha fish  (EXCL.wrapped/canned upto 2.5 kg )"            ""                           504311.12
""                                                                                "IN: INDIA"                  504311.12
"03033390: Frozen Sole, (Excl.Livers & Roes),nes"                             ""                            50458.58
""                                                                                "CN: China"                   50458.58
"03038990: Other fish, excluding livers and roes :"                               ""                          4243506.84
""                                                                                "AE: United Arab Emirates"    84116.63
""                                                                                "AU: Australia"              138323.76
""                                                                                "CA: Canada"                  70115.55
""                                                                                "CN: China"                     915880
""                                                                                "DE: Germany"                 21455.36
""                                                                                "GB: Great Britain"          831285.73
""                                                                                "IT: Italy"                  233858.95
""                                                                                "JO: Jordan"                  65583.08
""                                                                                "KR: Korean Republic of"      58984.96
""                                                                                "KW: Kuwait"                  67614.43
""                                                                                "MY: Malaysia"               192607.72
""                                                                                "NL: Netherlands"             25632.46
""                                                                                "QA: Qatar"                  164491.89
""                                                                                "SA: Saudi Arabia"          1002314.52
""                                                                                "US: United States"           371241.8
"03055990: OTHER DRIED FISH(EXCL.COD),NES"                                        ""                           166450.31
""                                                                                "IN: INDIA"                  166450.31
"03056990: Other Fish,Nes,Salted Salted Or In Brine But Not Dried Or Smoked, Nes" ""                           119446.85
""                                                                                "HK: Hong Kong"              119446.85
"03061100: Frozen Rock Lobster And Other Sea Crawfish"                            ""                             6886.35
""                                                                                "QA: Qatar"                    6886.35
"03061400: Frozen Crabs"                                                          ""                          3213895.72
""                                                                                "AU: Australia"               79230.57
""                                                                                "CA: Canada"                  40402.58
""                                                                                "CN: China"                 2288201.33
""                                                                                "GB: Great Britain"           99626.19
""                                                                                "HK: Hong Kong"               48740.33
""                                                                                "KR: Korean Republic of"      32750.13
""                                                                                "NL: Netherlands"             59347.81
""                                                                                "TW: New Taiwan"              15673.83
""                                                                                "US: United States"          549922.95
"03061700: Other shrimps and prawns"                                              ""                         31080776.67
""                                                                                "AE: United Arab Emirates"    87445.35
""                                                                                "BE: Belgium"               7772140.56
""                                                                                "CA: Canada"                 179255.42
end