I am using Amelia to generate five new hypothetical data sets for each variable with missing data. Now, I want to create new variables after imputation.
The reproducible dataset is in the Zelig package.
require(Zelig)
require(Amelia)
data(freetrade)
year country tariff polity pop gdp.pc ...
1 1981 SriLanka NA 6 14988000 461.0236
2 1982 SriLanka NA 5 15189000 473.7634
3 1983 SriLanka 41.3 5 15417000 489.2266
creating 5 imputed datasets with Amelia II
a.out <- amelia(freetrade, m=5, ts="year", cs="year")
transforming imputed variables
I learnt how to create transformations of the imputed variables for use in further analysis, see 4.8. in the manual. For instance:
a.out<-transform(a.out, pol_gdp = polity * gdp-pc)
a.out<-transform(a.out, pol.gdp = polity / gdp)
head(a.out$imputations[[1]])
year country tariff polity pop gdp.pc ... pol_gdp pol.gdp
1 1981 SriLanka 39.55176 6 14988000 461.0236 2766.142 0.013014518
2 1982 SriLanka 55.70500 5 15189000 473.7634 2368.817 0.010553791
3 1983 SriLanka 41.30000 5 15417000 489.2266 2446.133 0.010220214
...
PROBLEM
I do not know how to create a new variable depending on the value in another variable. That is, usually I would use the if-else argument, which does however not work in Amelia.
a.out$imputations$new.var<-ifelse(a.out$imputations$polity==5,1,0)
Any ideas would be highly appreciated!
Many many thanks.