Dear Statalist members,
I am trying to set up a loop function, but so far my efforts have been fruitless. The loop function should add, depending of the value in column "k", "value of k" lagged values of variable sum_ed (I inserted the manual approach for illustrative purposes). Since k could have a maximum value of 25 I would prefer a loop function to work out the problem.
xtset c_id year, yearly
gen sum_ed = e+d
gen cum_ed = .
replace cum_ed = sum_ed if k == 0
replace cum_ed = sum_ed + L.sum_ed if k == 1
replace cum_ed = sum_ed + L.sum_ed + L2.sum_ed if k == 2
replace cum_ed = sum_ed + L.sum_ed + L2.sum_ed + L3.sum_ed if k == 3
replace cum_ed = sum_ed + L.sum_ed + L2.sum_ed + L3.sum_ed + L4.sum_ed if k == 4
I would be very grateful for any tipps how to solve my problem!
Best regards
Jan
Related Posts with Question regarding loop function.
P-ValueCan some one explain to me what this piece of code is doing? I know it is related to creating a P-Va…
List string values of multiple varlistsHi everyone, I am trying to list the string values of two varlists (med_other_ind* and med_name*) w…
Technical problem: A regression model runs slowlyHello, I am doing multilevel logistic regression models And I run into a problem when I add two slop…
Age Period Cohort analysis GraphsHi everyone! I have just fitted a regression model using apcfit command. I would like to build a gra…
How to use lnmvnormalden(M,V,X) function (natural logarithm of the multivariate normal density)?I need to calculate the (logs of) bivariate normal densities for a large number of observations on t…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding loop function.
Post a Comment