pandas and Stata 13 files

若如初见. 提交于 2019-12-19 10:25:19

问题


I have pandas 0.13.1 installed but pandas.read_stata() fails to read .dta files created in Stata 13 format, with the error

TypeError: cannot concatenate 'str' and 'NoneType' objects

No problem at all with the same dataset saved in Stata 12 format.

I thought that the latest release of pandas (0.13.1) handled Stata 13 dataset files. Am I doing something wrong?


回答1:


My guess is you're not doing anything inherently wrong, but that your version of pandas can't handle Stata 13 dataset files. As documented in help dta, the format of Stata .dta datasets changed with the release of Stata 13.

Solution 1.

Update your pandas to v0.14.0 (May 31 , 2014):

read_stata now accepts Stata 13 format (GH4291)

Source: http://pandas.pydata.org/pandas-docs/stable/whatsnew.html

Solution 2.

If you have access to Stata, there are several ways of reverting to earlier/different formats that should work with your earlier version of pandas. See this answer:

Read Stata 13 file in R

Edit

Solution 3.

After some discussion in GitHub the problem pandas seems to have with Stata 13 datasets are string variables. So another solution could be converting the string to numeric type. See help encode, which will create appropiate value labels; or maybe help real or help destring, if the strings happen to be just numbers in string type.



来源:https://stackoverflow.com/questions/24053652/pandas-and-stata-13-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!