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
Related Posts with Keep running a replace command until (0 real changes made)
wanted = 1 if cumulative 15 trading days of risk = 1Dear All, I found this question here https://bbs.pinggu.org/thread-7813996-1-1.html。The data set is …
Multiple loop commands into one, "program error: code follows on the same line as open brace”Hi everyone, I have a panel data set that consists of portfolio weights of 25 different currencies …
Extension of maximum number of variables by "maxvar" is not possible:I have Stata 15 with a Stata/SE license. So extension of memory space should be possible. However us…
Transforming data in a Correlation MatrixDear all, I'm having a 410x410 correlation matrix, which looks like this A B C D A 1 0.1 0.2 …
How to test moderating effect in time series analysis?Hi all, I am beginner in analyzing data with STATA. I have some problem to choose the suitable meth…
Subscribe to:
Post Comments (Atom)
0 Response to Keep running a replace command until (0 real changes made)
Post a Comment