Title

makecd -- Create command to changes the working directory
and set up a project environment

General syntax

makecd [cd]project [,
note(string)
autorun(command-name)
data(path-name)
data2(path-name)
url(web-address)
user(string)
noslash
details
replace]

Options

note(string) describes the command being created.

autorun(command) is command to be run by
cdproject.

data(path-name) is a path for datasets; saved
in global macro S_cddata.

data2(path-name) is a second data path; saved
in global macro S_cddata2.

url(web-address) is web address; saved
in global macro S_cdurl.

user(string) is a any string; stored
in global macro S_cduser.

noslash prevents slash from being added to end of paths and URLs.

details displays globals macros created by cdproject
commands.

replace replace ado file if it exists.

Commands names must start with cd. You can enter
the name as cdproject or as project;
if needed, cd is added to the name.
Since names of global macros begin with
S_ they are not dropped by clear all or
macro drop _all. To drop then, run macro drop global-name.

Overview

makecd creates (i.e., makes) an ado file cdproject.ado
that changes your working directory, creates global macros, and
automatically runs a command specified by auto().
The cdproject.ado commands are saved in the PERSONAL directory.

By creating multiple
cdproject commands, you can easily
have different working directories for each
project with optional data locations for each project. The
listcd command lists your cdproject commands along with
the the working directory it sets or the note
added as an option to makecd.
The dropcd command deletes selected cdproject commands
from PERSONAL.

Creating and using a cdproject command

1. Change to a working directory. For example,

. cd d:/paper/work

d:/paper/work

2. Decide on a project name associated with the working directory,
such as paper and create
the command cdproject command using
makecd. For example,

. makecd paper

command cdpaper saved in your PERSONAL directory

Since the command is saved in PERSONAL, Stata will find it
when you run the command from any working directory:

3.To change your working directory, run your cdproject
command which will echo the path of the working directory. For example,

. cdpaper

d:/paper/work

Using globals for datasets not in the working directory

By default, use loads a dataset from the working
directory and save saves a dataset to the working directory.
To load a dataset from the path specified by the data() option
in makecd,

use "$mydata", clear

To load a dataset from the directory specified by the data2() option,

use "$mydata", clear

You can save datasets to the data directorys with command such as

save "$mydata", clear

save "$mydata", clear

To load a dataset from the URL specified by the url() option,

use "$mydata", clear

Automatically running a command for each project

The autorun(command) option lets you specify a command that is run
by cdproject after it changes the working directory and creates
global macros.
Thc command could be something like auto(dir *.dta)
or auto(do project-setup).

Controlling the starting working directory

You can create the command cdstart with makecd and
add cdstart to your profile.do to make the directory
set by cmdstart the starting directory in Stata.
You can replace the existing cdstart to have Stata begin in
a different directory.

Globals

cdproject commands create these globals:

S_cdcmd name of cdproject command.

S_cdauto command to be run by cdproject.

S_cddata data directory path.

S_cddata2 second data directory path.

S_cdurl web address.

S_cduser any string.

S_cdwd working directory set by cdproject.

Citation

J. Scott Long. 2017.
A Workflow for Changing Working Directories and Managing Projects.
http://www.indiana.edu/~jslsoc/