Skip to content

Instantly share code, notes, and snippets.

@larsvilhuber
Last active October 23, 2023 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsvilhuber/afec296033d90ae21e1440f00095bfb2 to your computer and use it in GitHub Desktop.
Save larsvilhuber/afec296033d90ae21e1440f00095bfb2 to your computer and use it in GitHub Desktop.
Conditional Stata download
// this would be the directory to put data
global root : pwd
global data "$root/datadir"
cap mkdir "$data"
// now to the file in question
global nhtsfile "nhts-ascii.zip"
capture confirm file "$data/$nhtsfile"
if _rc != 0 {
// what to do when file does NOT exist
copy https://nhts.ornl.gov/2009/download/Ascii.zip "$data/$nhtsfile"
}
// might want to also test for a "trigger" file
// to not unnecessarily unzip again
cd "$data" // Stata cannot unzip into a different directory, so we have to
// deviate from our rule to never use "cd"
unzipfile "$nhtsfile"
cd "$root"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment