Dear all, I have this simplified dataset

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year byte month double(variableR variableS)
2010  1                      .                     .
2010  2                      .   .010959871357460016
2010  3                      .    .01354375369990641
(cont.)
(cont.)
(cont.)
2013  1                      .  -.016088098299477386
2013  2  -.0006724906442758776   .012724059958391246
2013  3    .011248911675399098   .013520731757268062
2013  4   .0016660546292909867  -.009432963884234489
(cont.)
(cont.)
(cont.)
end
Both variables (who are doubles) have missing values at the first observation. However, note that variableR has missing observations until 2013 1.

When I attempt to do the following code

Code:
global sample variableR variableS

foreach i of global sample{
g ln`i'=ln(100) if year==2010 & month==1
replace ln`i'=ln`i'[_n-1]+`i' if _n>1
g new`i'=exp(ln`i')
}
keep newvariableR newvariableS year month
I get these results. Although the first line is correct for both variables, however, the variableR which had missing rows for _n>1, the entire rest of the column missing.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year byte month double(variableS variableR)
2010  1 100.00000000000004 100.00000000000004
2010  2 101.10201507644511                  .
2010  3 102.48063060821141                  .
2010  4 102.70110116953431                  .
2010  5 101.83968833087879                  .
2010  6 101.16437738561285                  .
(cont.)
(cont.)
2014 10 116.02554866782972                  .
2014 11 115.59111847676228                  .
2020 10 112.76718492948326                  .
end
How do I tell stata in this line of code

Code:
replace ln`i'=ln`i'[_n-1]+`i' if _n>1
to return me a missing value . if `i` is missing? Altering code to this

Code:
replace ln`i'=ln`i'[_n-1]+`i' if _n>1 & `i` !=.
does not solve it.