I have the following panel data (in total 1200 observations)
Country | Year | ACC_POP | ACC_RUR | countrynum |
Angola | 2013 | 36.99049 | 16.2722368 | 1 |
Angola | 2014 | 32 | 3 | 1 |
Angola | 2015 | 42 | 7 | 1 |
Angola | 2016 | 40.520607 | 15.9842091 | 1 |
There are obviously mistakes in the observations: ACC_RUR is able to change, but cannot change from 16.27 to 3 from 2013-2014 and to 7 from 2014-2015 and then to 15.98 in 2016. 2013 and 2016 seem to be correct.
I want to replace data if they are too far from previous or following values, for instance, how do I change ACC_RUR for 2014 and 2015 to 15.98
I have tried replacing them with the following value (in this case if the value is off by 5), using:
bysort countrynum(Year): replace EL_ACC_pRUR[_n-1]=EL_ACC_pRUR if EL_ACC_pRUR-5>EL_ACC_pRUR[_n-1]
and get the error: "weights not allowed". Fair play, weights not allowed.
Does anyone have an idea on how to correct this or run another replace code that allows for changes inside an interval (30 percent for instance)? Have in mind that this needs to be done for many observations.
A direction to another forum with the similar issue is also appreciated. Of course, I have searched for this beforehand but could not find any.
Best,
Andreas
0 Response to Replacing value with previous value if value is outside certain interval
Post a Comment