Virata manual

save

Writes the dataset in memory out to a file.

What we have

  • .dta and .csv
  • labels are kept in a .dta, so use gives back what you had
  • replace, and a refusal to overwrite without it

Coming later

  • .parquet needs pyarrow installed yourself
  • saveold, and choosing which Stata file version to write
  • compress, choosing smaller storage types

How you write it

save "file.dta" [, replace]

Square brackets mean optional. A vertical bar means choose one.

What it does

Saves everything: the values, the variable names, the descriptions you attached with label variable, and the words that stand in for coded numbers (value labels). Reading it back with use gives you exactly what you had.

Without replace it refuses to write over a file that already exists. That refusal is deliberate — it is the difference between saving your work and losing a morning of it.

Try it

Every example below was run after sysuse vira.sample02, clear.

. save "kept.dta", replace
file kept.dta saved
The same thing in pandas and in R

pandas

df.to_stata("kept.dta", write_index=False)

R

library(haven)
write_dta(df, "kept.dta")

# This R has NOT been run against a real R yet: read it as documentation.

Nearby

use sysuse import export clear browse