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
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
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
Code:
replace ln`i'=ln`i'[_n-1]+`i' if _n>1
Code:
replace ln`i'=ln`i'[_n-1]+`i' if _n>1 & `i` !=.
0 Response to Using replace produces wrong result
Post a Comment