Tuesday, February 1, 2011

STATA: Tempfile

-tempfile- creates a local containing a file address. This file will automatically be removed by Stata once your do file ends, so you don't have to worry about cleaning up your mess. It will always (except for rare occasions in Stata 9 at least when it would mess up) be unique, even if you run two copies of the same do file simultaneously. In short, they're cool.

All -tempfile- does is create the local. It's exactly like if you'd created a local containing a file that you want to exist but that doesn't yet exist. If you want to have a file already existing (e.g. for using with -append- in a loop), check out -findit touch-.

If you call -tempfile- twice with the same name, the first file is gone forever, replaced with a new pointer to a temporary file. This is good in loops.

tempfile c2file
use $xdrive/projects/SeattleStinks/countries_original, clear
rename ex0 ex0_original
sort iso
save `c2file'
use $xdrive/projects/SeattleStinks/countries_new, clear
sort iso
merge iso using `c2file'

1 comment:

  1. The great thing about PDF documents is that they can be modified from a computer in any office or home. For more ideal details about find hidden files, pop over to these guys.

    ReplyDelete