A Package to read and write Stata .dta files.
This may be the first Julia DataFrame to Stata conversion program.
Despite the excellent .dta file reader in ReadStat.jl package,
I needed to write another .dta file reader because ReadStat.jl
was not able to handle very large files well and all formats such as value labels
and date and datatime formats are lost during conversion. It is written entirely in Julia.
StataIO.jl provides the following functionalities:
-
When importing, it can break large files into small chunks and so can handle very large files gracefully in memory strapped situations. Use
chunksoption to specify the number of chunks to use (default = 10). -
All variable labels will be imported using
TableMetadataTools.jl. -
All variables with value labels will be imported into
CategoricalArrays. Ifkeep_original = falseis set, only the value labels will be imported and the original numeric values will NOT be kept. If you want to keep the original values, usekeep_original = true. Then, original Stata numeric values will be prepended to the value labels followed by a:(default:false). -
All
intorlongvariables with%dor%tdformats will be imported as Julia dates using theDatespackage. -
All
floatordoublevariables with%tcor%tCformats will be imported as JuliaDateTimevariables. -
When exporting, Julia Dates and DateTimes will be automatically converted to Stata with the formats
%tdNN-DD-CCYYfor dates and%tcfor datetimes. -
CategoricalArrays will be exported into
byteorinttypes with all value labels. -
Any variables with data types that are not supported by Stata (e.g., Int64) will NOT be exported.
] add StataIO
df = read_stata(Statafilename::String; chunks::Int = 10, keep_original = false)
write_stata(Statafilename::String, df::AbstractDataFrame)