Hello Amelia users
I have tried to use the amelia package, and I got the following error. I am
dealing with a macro panel dataset for 126 countries and 16 years. I want
to impute using the entire dataset, the values of time to export, time to
import (measured in hours), and cost of exports and imports in USD.
The proportion of missingness is quite large around 45 and 65 % for the
variables. For that purpose, I use the option empri, read Amelia manual on
page 31.
am = amelia(final_datos1, m = 5, intercs = TRUE, empri =
.01*nrow(final_datos1), cs = "country", ts = "year")
After running this, it gives me the error
Warning message:
In amcheck(x = x, m = m, idvars = numopts$idvars, priors = priors, :
The variable year is perfectly collinear with another variable in the
data.
It seems to me that this is due to the fact that for the combination of
country and year, there are missing values for all variables
Any help is appreciated
--
Member, Editorial Committee, *The Economic and Labour Relations Review* (a
SAGE journal)
http://elr.sagepub.com/
Member, Editorial Committee, African Journal of Economic and Management
Studies
http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=a…https://www.researchgate.net/profile/Antonio_Andres (Research Gate profile)
I have a multiply imputed dataset (imputed using Amelia) and would like to derive a function which runs several regressions (with the same outcome, and different predictor variables) in one go. The reason is that I need to run several regressions (with the same predictors) on different outcome variables.
I have defined the function but when I run it, I get an error message:
Error in model.frame.default(formula = outcome ~ country, data = as.data.frame(.), : variable lengths differ (found for 'country')
I think it is because the imputed datasets are an "amelia" object and not a typical data frame, so it is hard to index the variable "country". But I'm not sure how to do this.
A reproducible example is below. I would really appreciate any advice.
library(Amelia)
library(Zelig)
# Use africa dataset
data(africa)
# Impute data
imp.out <- amelia(x = africa, cs = "country", ts = "year", logs = "gdp_pc", m=5)
summary(imp.out)
# Define function to run regression predicting an outcome from country, gdp_pc, civlib, and population
reg_function <- function(outcome, data) {
# Run regressions using the zelig function
country <- zelig(outcome ~ country, model = "normal", data=data, cite=FALSE)
gdp_pc <- zelig(outcome ~ gdp_pc, model = "normal", data=data, cite=FALSE)
population <- zelig(outcome ~ population, model = "normal", data=data, cite=FALSE)
# Put results into a vector
results <- ( c(combine_coef_se(country)[2,1], combine_coef_se(country)[2,2],
combine_coef_se(gdp_pc)[2,1], combine_coef_se(gdp_pc)[2,2],
combine_coef_se(population)[2,1], combine_coef_se(population)[2,2]))
# Return results in a matrix
return(matrix(results, nrow=1, ncol=6, dimnames=list(c(""),
c("Est_country", "SE_country",
"Est_gdp_pc", "SE_gdp_pc",
"Est_population", "SE_population"))))
}
# Run regression for outcome variables "year", "infl", and "trade"
# This is where I get the error messages that the variable lengths differ for 'country'
year <- reg_function(year, imp.out$imputations)
year <- reg_function(infl, imp.out$imputations)
year <- reg_function(trade, imp.out$imputations)