with open("C:\Test\Old.dta", "a") as outfile: a = pd.read_stata("C:\Test\New.dta") a.to_stata(outfile,write_index=False)

This there a way to append a dta file to another using something like this?

Comment From: jreback

cc @bashtage

Comment From: bashtage

The stata dta format is not readily amenable (I am assuming you would like to add new values to existing variables) since it looks like

metadata (including value indicating number of observations)
numeric data and some string data
value labels

Amending would require overwriting the value labels, updating them if needed, and the finally writing the new value labels. There is also a variable nvars in the header that would need to be overwritten. Not worth the effort to try and implement this -- the design of the .dta spec was not intended for amending IMO.

Assuming are the same (same columns, same dtypes), the one liner will work:

pd.concat([pd.read_state(f) for f in dta_files]).to_stata('concat.dta',index=False)

If you want to add new variables (rather than new values), this is completely impossible to implement in the dta format.

Comment From: jreback

ok, closing. @rhysjohnmiller if you want to a note to the docs / doc-string would be fine.

Comment From: rhysjohnmiller

Thank you for the help!