Good evening everyone,

I do have the closing prices NAV (net asset value) and I calculate the return as follows: nav_ret=ln(nav/nav[_n-1]. I try to find a way to create a new variable that compounds the interest on daily basis starting as base the value 100. In the data example variable base has to start with 100 and continue till the end. When I try to loop like this all values in base are reported as missing.

Code:
levelsof n, local(ns)
foreach x in `ns' {
replace base=base[_n-1]*nav_ret+base[_n-1]
}

Code:
input str7 ticker double nav float(datenum nav_ret n base)
""             .     .            .  1       100
"CBDJIUS" 106.12 18415    .02239362  2 102.23936
"CBDJIUS" 101.64 18420   -.01163998  3  101.0493
"CBDJIUS" 102.95 18421   .012806275  4 102.34337
"CBDJIUS" 102.52 18422 -.0041855318  5         0
"CBDJIUS" 105.34 18423    .02713531  6         0
"CBDJIUS" 105.77 18424   .004073711  7         0
"CBDJIUS" 105.55 18427 -.0020821511  8         0
"CBDJIUS" 107.76 18428    .02072176  9         0
"CBDJIUS" 107.81 18429 .00046388645 10         0
"CBDJIUS" 108.07 18430   .002408747 11         0
end
format %td datenum
In the code above the base the obsevations 2/5 are calculated manually by command:

Code:
replace base=base[_n-1]*nav_ret+base[_n-1] in 2
replace base=base[_n-1]*nav_ret+base[_n-1] in 3
replace base=base[_n-1]*nav_ret+base[_n-1] in 4
Is there any way to fix the loop?