Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ENH: Add class to write Stata binary dta files #526

Merged
merged 17 commits into from Oct 12, 2012

Conversation

Projects
None yet
1 participant
Owner

jseabold commented Oct 8, 2012

This needs a little polishing but works for now for the below simple case. Should round trip the same.

dta = sm.datasets.macrodata.load().data
dtype = dta.dtype
dta = dta.astype(np.dtype([('year', 'i8'),('quarter', 'i4')] + dtype.descr[2:]))
writer = StataWriter("./try_dta.dta", dta)
writer.write_file()
dta2 = genfromdta('./try_dta.dta')

TODO:

  • Docstrings
  • Test on Python 3
  • Test with different encoding for strings - not handled yet
  • Test with object arrays
  • Test with datetime types - will need to convert to Stata time integer
  • Add support for pandas objects
  • Handle missing values
Owner

jseabold commented Oct 9, 2012

All the TODOs are addressed and tested except Python 3 and unicode. This is ready to merge if we're happy with the API and tests pass on Python 3. I'm not entirely happy with the API, but I only really see this being useful for pandas objects and structured arrays. Since I seriously doubt anyone is going from structured array to dta, I'll focus on getting the API right with a PR to pandas. I'll also fix the unicode support there too and stick it back in here.

Owner

jseabold commented Oct 12, 2012

Would like to go ahead and merge this. It's not perfect and I will probably continue to work on it incrementally - testing in production..., but I could use it for work right now. If this is not a great reason to merge, then I could figure something else out.

@jseabold jseabold added a commit that referenced this pull request Oct 12, 2012

@jseabold jseabold Merge pull request #526 from jseabold/stata-writer
ENH: Add class to write Stata binary dta files
25c8b7c

@jseabold jseabold merged commit 25c8b7c into statsmodels:master Oct 12, 2012

@PierreBdR PierreBdR pushed a commit to PierreBdR/statsmodels that referenced this pull request Sep 2, 2014

@jseabold jseabold Merge pull request #526 from jseabold/stata-writer
ENH: Add class to write Stata binary dta files
04f9dc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment