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.
split, parse(,) maximum number of variables reachedDear all, I'm using Stata 15 and trying to split a string variable into different component which ar…
Regression output - Bug?Hi everyone, I am trying to run some old code (version 14.2) using a new Stata version (15.1) on a …
Random dummy variable with restrictionsI have a panel dataset and want to create a random dummy variable with mean 0.2 that marks a random …
Outreg2 providing one-sided p-valuesDear Stata users, I have a question regarding the one-sided p-value in outreg2, which I use to expo…
Multi-column heading in outreg2Hi everyone, Using outreg2, is it possible to create a column heading that spans several columns of…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding loop function.
Post a Comment