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)
PPMLDHFE dropping linear time trendHi all, I'm trying to run the following code: Code: ppmlhdfe died year `controls' if year!=2020,…
Dropping variablesHi Guys, Need help with dropping a variable. This is my data: ccode ifscode country group region i…
And how to write the following more efficiently: reg dep zipf6 zipf7 zipf8 zipf9 zip11 ind6 ind7 ind8 ind9 ind11And how to write the following more efficiently? reg dep zipf6 zipf7 zipf8 zipf9 zip11 ind6 ind7 in…
How to write a more efficient code calculating a weighted index?Hi, I use the following code to calculate a weighted zipf index: gen zipfindlight`var' = zipf13*in…
Anchor the tssmooth command at start pointHi - I have a dataset with daily observations over 240 sequential days. Is there a way to calculate …
Subscribe to:
Post Comments (Atom)
0 Response to Keep running a replace command until (0 real changes made)
Post a Comment