I dealing with data like:
0 2 4
-1 0 1
-2 -1 0
i wanna generate all data t`i'*w[_n] but minus one would multiple with var ww not w,so i use code like this
Code:
gen BP=0
forvalues i=1(1)3 {
if t`i'>=0{
gen a=t`i'*w[_n] if t`i'>=0
egen a2=total(a)
replace BP=a2 if code==`i'
drop a a2
}
else{
if `i'<=3{
local j=`i'+1
local i=`j'
}
}
}
and i got half right result,but when i use code based on it, the loop only works once.the second code is follwing:
Code:
gen BN=0
forvalues i=2(1)3 {
if t`i'<=0{
gen a=t`i'*ww[_n] if t`i'<=0
egen a2=total(a)
replace BP=a2 if code==`i'
drop a a2
}
else{
if `i'<=3{
local j=`i'+1
local i=`j'
}
}
how could i fix it?