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.
Effect of a policyHi there, I need to work out the effect of a policy that was introduced in 2007, which raises the to…
Special character in Variable labels (German "ä", "ö", "ü", ...)I'am importing a ".dta dataset created by another Software (maybe SAS) and everything workes fine, a…
2sls regressionGood afternoon. I have a dataset with these information: - education: dummy skilled/not skilled - A…
Year omitted becuase of collinearity (DID)Hi, I am doing DID regression. I have 12 years of data. I have included 'year' variable for fixed y…
How to create observations for missing yearsHey, I want to create new observations for missing years. For example, I have data on wages and mont…
Subscribe to:
Post Comments (Atom)
0 Response to Question regarding loop function.
Post a Comment