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.
fectWhy do I get different results every time I run fect? …
Different results OLS / GLS regression - how to choose the best modelHello! I'm writing a thesis on how director reputation changes overtime. Director reputation is der…
Is it possible to display chi-squared values in a table like this [example provided]Hi, I'm new to using stata (using Stata17), I'm currently trying to replicate this graph. I've succe…
Problems Diagnosing CollinearityHello. We have data, which from visual inspection, has the outcome variable (summarized over a group…
Different ATT results with outcomes coded as 0,1 and 1,2.Hi all, While running PSM with teffects psmatch in stata, I am getting different ATT when the exposu…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding loop function.
Post a Comment