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)
Resetting IndexHello, I have a panel dataset containing three vars: nation, year, and a variable called 'event' wh…
Forest plots - how do I move the null reference line in meta forest?Hi, I am trying to make a Forest plot of odds ratios. The studies cannot be combined, I'm only tryi…
Panel data with missing valuesHi everyone, I am wondering if anyone can suggest a method to analyze data in the following format: …
Trend graphs for repeated cross-sectional dataHi, I'm a student and I'm working with a repeated cross-sectional dataset. I would like to create so…
Sum Data from multiple variablesHello, I'm trying to create a new variable that is equal to the sum of several other variables. The…
Subscribe to:
Post Comments (Atom)
0 Response to Keep running a replace command until (0 real changes made)
Post a Comment