Hello!
I have a paneldata with the ages of individuals with around 50 million observations. The age of each individual should increase at the rate of 1 year per year, but it doesn't. Thus, I'm correcting this issue by checking if the increase (variable "delta") is different than 1. I'm also using a mode (egen tmp = mode(delta), by(ntrab)) of the delta to check if for at least some individuals, I have multiple years where the age increases at the correct rate. I then generate a new variable tmp2, which is simply to check if for two consecutive years the delta is equal to 1 (gen tmp2 = (delta == 1 & l.delta == 1)) and I replace the age variable (idade) to missing if tmp2 == 0. I then start correcting idade with the following code:
replace idade = f1.idade-1 if f1.idade ~= . & f1.tmp2 == 1
which basically goes to the first correct value and uses it subtracting one. This is an example of the data after running the code once. Stata has corrected the age for the year (variable ano) 2011, but I would need to run it again 3 more times until it corrects all years. Do note that this is an example and for some individuals I may have around 30 years, so I would actually like Stata to keep running the code until I get (0 real changes made). Is there anyway to do this?
Thanks for your time!
Hélder
ano | workerid | idade | delta | tmp | tmp2
2008 | 1 | . | -55 | 1 | 0
2009 | 1 | . | 57 | 1 | 0
2010 | 1 | . | -55 | 1 | 0
2011 | 1 | 21 | 1 | 1 | 0
2012 | 1 | 22 | 1 | 1 | 1
2013 | 1 | 23 | 1 | 1 | 1
2014 | 1 | 24 | 1 | 1 | 1
0 Response to Keep running a replace command until (0 real changes made)
Post a Comment