tessam30
7/10/2014 - 6:46 PM

Stata: Setting up a folder structure for a project. Creates project folders and global macros for use throughout project.

Stata: Setting up a folder structure for a project. Creates project folders and global macros for use throughout project.

/*------------------------------------------------------------------------------
# Name:		00_SetupFolderGlobals
# Purpose:	Create series of folders for a project
# Author:	Anon
# Created:	07/10/2014
# Revised:  07/10/2014
# Ado(s):	confirmdir, mvfiles, fs,
# Dependencies: none
#------------------------------------------------------------------------------*/

*Make directories for the study & sets global macros*
set more off

*install the confirm directory ado if not already installed
/*Notes: */
local required_ados confirmdir mvfiles fs lookforit adolist labellist mdesc
foreach x of local required_ados { 
	capture findfile `x'.ado
		if _rc==601 {
			cap ssc install `x'
		}
		else disp in yellow "`x' currently installed."
	}
*end

*Install list of adofiles needed for program
*To be completed once do files are drafted

*Determine path for the study (needs to be modified)
global projectpath "U:\"
cd "$projectpath"

*Run a macro to set up study folder (needs to be modified)
local pFolder ProjectName
foreach dir in `pFolder' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
		mkdir "`dir'"
		display in yellow "Project directory named: `dir' created"
		}
	else disp as error "`dir' already exists, not created."
	cd "$projectpath\`dir'"
	}
*end

*Run initially to set up folder structure
*Choose your folders to set up as the local macro `folders'
local folders Rawdata Dofiles Datain Log MetaData Output Dataout Excel PDF Word Graph GIS Export R
foreach dir in `folders' {
	confirmdir "`dir'"
	if `r(confirmdir)'==170 {
			mkdir "`dir'"
			disp in yellow "`dir' successfully created."
		}
	else disp as error "`dir' already exists. Skipped to next folder."
}
*end

/* Dependency: Make sure labvalsort2.do is installed in .do files folder */

/*---------------------------------
# Set Globals based on path above #
-----------------------------------*/
global date $S_DATE
local dir `c(pwd)'
global path "`dir'"
global pathdo "`dir'\Dofiles"
global pathlog  "`dir'\Log"
global pathin "`dir'\Datain"
global pathout "`dir'\Dataout"
global pathgraph "`dir'\Graph"
global pathxls "`dir'\Excel"
global pathreg "`dir'\Output"
global pathgis "`dir'\GIS"
global pathraw "`dir'\Rawdata"
global pathR "`dir'\R"
global pathMeta "`dir'\MetaData"
macro list 

/*----------------------------------------------- 
#Copy contents of data folders in Rawdata folder #
-------------------------------------------------*/