Your cart is currently empty!

In many cases, Stata users need to create files that are only used temporarily. Examples are if you have a loop to clean year-specific data which then needs to be appended to create a panel dataset, or if you need to aggregate data at some level and then need to merge m:1 it to individual level data.
This can obviously be done by just storing the data as a regular file and then to do the merge/append command (and possible to erase the file later on). But this requires more time (as well as an extra command if you want to erase the file afterwards) than if you use Stata’s temporary files. The usage of temporary files in Stata is quite straightforward:
use mydataset.dta
/* do whatever you need to do */
tempfile mytempfile
save `testfile'
You can then use the temporary file as you would use a regular file, e.g. with
merge m:1 pers_id using `testfile'
And you can of course test how much time you save with this approach. Just run
di "1: Temp file save"
timer on 1
use mydataset.dta
tempfile mytempfile
save `testfile'
timer off 1
di "2: Regular save"
timer on 2
use mydataset.dta
save mytempfile
timer off 2
timer list
That is it!