Good morning,
I'm trying to replace missing value with loop, but it doesn't work well. It just replaces the first missing value and let the others unchanged. Here is my code
Thank you in advance for your help
I'm trying to replace missing value with loop, but it doesn't work well. It just replaces the first missing value and let the others unchanged. Here is my code
Code:
foreach v of varlist GDP-Export { { gen `v'_new = `v' if `v'_new[_n-1]!=.{ by id (time), sort: replace `v'_new= `v'_new[_n-1] if missing(`v'_new) } else{ by id (time), sort: replace `v'_new= `v'_new[_n+1] if missing(`v'_new) } } }
Comment