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.
Dyadic Ties. Looping if a pair in the same group is also a pair in another group, not longer than five years before the focal groupI am using Stata 15.0 I am trying to construct the variable Prior Tie Density (the number of formed …
Panel Data Missing Observations! SolutionDear Statalisters, I am currently running analysis on a 2-period panel data set from China. I use a…
Using Wald Test for Complex Interaction ModelsDear all: My name is Siyu. I am running a random-effects logit model involving many interaction ter…
Help with time-invariant variable in panel dataGood morning, I am new here and would greatly appreciate some help. I would like to run a regressio…
rename all words of localDear all, I have trouble finding my way through all possible local manipulations to find what I nee…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding loop function.
Post a Comment