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)
Change legend automatically in graphDear Statalists, Suppose I have a data like this Code: * Example generated by -dataex-. To insta…
Putting labels for different variables in one line of code or loop?Hello, I would like to add labels for a set of different variables, i have around 15, and would lik…
New packages available on SSC: comtrade and htmltab2stataThanks two Kit Baum two new packages are available on SSC. comtrade comtrade downloads trade data f…
New packages cprdonsutil and cprdlsoautil on SSCThanks as always to Kit Baum, 2 new packages cprdonsutil and cprdlsoautil are now available for down…
Test for sufficient sample size in linear probability modelHi, I run the following linear probability model: Code: reg nodad k1sex i.meduc i.state i.mdecade…
Subscribe to:
Post Comments (Atom)
0 Response to Keep running a replace command until (0 real changes made)
Post a Comment