Skip to Main Content

Data Analysis with Stata

tempfile

If you need to save changes to the data for later use in the same session, but want to avoid creating dozens of intermediate files on your hard drive, save them as temporary files. An example:

* make changes to daily calorie data and save the data in a tempfile
use "https://www3.nd.edu/~jng2/libguide/dailycalories.dta", clear
gen statadate = date(day, "DMY")
label var statadate "date in days elapsed since 1-Jan-1960"
tempfile cal
save `cal'

* merge the tempfile to weather data
use "https://www3.nd.edu/~jng2/libguide/dailytemp.dta", clear
nsplit yearmoda, digits(4 2 2) generate(yyyy mm dd)
gen statadate = mdy(mm, dd, yyyy)
merge 1:1 stn statadate using `cal'

Note that the nsplit command is user-written and can be installed using ssc install nsplit

.

Screencast produced by the Office of Digital Learning