Code:
* Impute unemployment sort countrycode year replace unemployment_wb = (unemployment_wb[_n-1] + unemployment_wb[_n+1])/2 if unemployment_wb == . & countrycode == countrycode[_n-1] & countrycode == countrycode[_n+1] replace unemployment_wb = (unemployment_wb[_n-2] + unemployment_wb[_n+2])/2 if unemployment_wb == . & countrycode == countrycode[_n-2] & countrycode == countrycode[_n+2] replace unemployment_wb = (unemployment_wb[_n-1] + unemployment_wb[_n+1])/2 if unemployment_wb == . & countrycode == countrycode[_n-1] & countrycode == countrycode[_n+1] replace unemployment = (unemployment[_n-1] + unemployment[_n+1])/2 if unemployment == . & countrycode == countrycode[_n-1] & countrycode == countrycode[_n+1] replace unemployment = unemployment_wb if unemployment == . & unemployment_wb != . replace unemployment = (unemployment[_n-1] + unemployment[_n+1])/2 if unemployment == . & countrycode == countrycode[_n-1] & countrycode == countrycode[_n+1] replace unemployment = (unemployment[_n-2] + unemployment[_n+2])/2 if unemployment == . & countrycode == countrycode[_n-2] & countrycode == countrycode[_n+2] replace unemployment = (unemployment[_n-1] + unemployment[_n+1])/2 if unemployment == . & countrycode == countrycode[_n-1] & countrycode == countrycode[_n+1]
0 Response to Adding flag for imputed missing value
Post a Comment