Hi Sophie,
It seems like there is a string variable in your dataset that has a blank
value ("") which causes problems for Stata. Given the SO link you sent,
there are a couple of options. One would be to convert the strings to
factors in the original dataset before passing it to Amelia. Then they will
be factors when you go to save the dataset and it shouldn't cause any
problems.
Second, you could do the conversion on the Amelia output using a similar
strategy to the one in the SO post with an additional loop:
for (i in 1:a.out$m) {
for (colname in names(a.out$imputations[[i]])) {
if (is.character(a.out$imputations[[i]][[colname]])) {
a.out$imputations[[i]][[colname]] <-
as.factor(a.out$imputations[[i]][[colname]])
}
}
}
Just replace "a.out" with whatever the name of your amelia output is.
Hope that helps!
Cheers,
Matt
~~~~~~~~~~~
Matthew Blackwell
Assistant Professor of Government
Harvard University
url:
http://www.mattblackwell.org
On Sun, Jun 19, 2016 at 9:31 AM, Sophie C. Moullin <smoullin(a)princeton.edu>
wrote:
Dear Amelia users/creators,
I want to write a stack of Amelia imputed data sets into a Stata format
for some specific analyses and tests that I find easier in Stata.
I know that write.amelia enables this when the separate argument is set to
false, and have tried the following code:
write.amelia(am.output, format="dta", file.stem="outdata",
separate=FALSE,
orig.data=TRUE)
However, I get an error message: “Error in write.dta(dataframe= list…)
empty string is not valid in Stata's documented format”.
Stack overflow has a thread on this error for write.dta, which suggests
overwriting a data frame, however I cannot do this with the Amelia output:
http://stackoverflow.com/questions/27574055/converting-r-file-to-stata-with…
<https://urldefense.proofpoint.com/v2/url?u=http-3A__stackoverflow.com_questions_27574055_converting-2Dr-2Dfile-2Dto-2Dstata-2Dwith-2Dmissing-2Dstring-2Dvalues&d=CwMF-g&c=WO-RGvefibhHBZq3fL85hQ&r=EwICq0J5pL8CwgEJz8qkmauGonk0XmiLpxcYOEgk2a0&m=xRTg_4x21W_VBsoE1S7MyUdURmErjtcoUzqWNAElULc&s=OMvXImiZ9taEuEFVqrJFdhB9hlRD4ZGJkpl0y3kN3Ac&e=>
Any advice?
Grateful for this great MI package, and for any suggestions!
Sophie
Sophie Moullin
Sociology & Social Policy PhD Student
Princeton University
smoullin(a)princeton.edu
--
Amelia mailing list served by HUIT
[Un]Subscribe/View Archive:
http://lists.gking.harvard.edu/?info=amelia
More info about Amelia:
http://gking.harvard.edu/amelia
Amelia mailing list
Amelia(a)lists.gking.harvard.edu
To unsubscribe from this list or get other information:
https://lists.gking.harvard.edu/mailman/listinfo/amelia