What’s the objective?
The intention of the following setup is for many individuals to be able to run the same exact code - without changing file paths - on any device, regardless of the commands installed. Hence, it is a way to keep things universal across devices and users. This setup is essentially a more basic version of Julian’s Reif stata guide. Notice that this requires a service like Dropbox (it can be anything, though). For example, a given do-file for a project would start like this and will work in all computers
*=============================
* Open Settings
*=============================
medicaidracial
adopath ++ "$root/analysis/scripts/statapackages"
net set ado "$root/analysis/scripts/statapackages"
*=============================
* Code Starts
*=============================
How does it work?
In short, what we are going to do is (1) create a file that lives in each device that makes the globals of where Dropbox, box, Google Drive, or any other type of service lives. This file is a file that is automatically always run when you run STATA. This is the main trick because once you open STATA and have already created a global for Dropbox, since the file paths within Dropbox will be the same, everything will work from then on.
The second part (2) is to create a do-file stored in each PC, where we can set up a program to call the globals for each specific project. It would be great if the folder structure were different for each project.
The third part (3) is to create a pre-amble in every code to make the results in a folder corresponding to each month. This way, we can keep track of any output produced over time.
Once this is set up, it should be done on all computers for all users in the project.
Please follow the guide on how to use Notion for Sebastian’s project for a guide on how to keep up the project's progress.
Step 1: Create the profile.do
When you open STATA, you may notice the following line:
This is saying that once you run STATA, you always run that do-file. If this doesn’t happen, then you want to create one.
Step 3: Create the programs for each project.
Now that you created profile.do, you should create your “stata_profile.ado”. An ADO is very similar to a do-file, just with an .ado extension. You don’t need to know the difference for this to work. So the stata_profile.ado file will have all the “programs” for each project. What are the programs? These are commands that call into the a number of globals that there are program specific.
The steps are the same for mac or windows:
- Create a do-file called and save it as “stata_profile.ado”
- Put the file in our of your share drives folder (dropbox, box, google drive).
- If you put it outside of these folders, then every time you edit this file you will have to edit it in all PCs, hence it’s better to put it in a shared-drive service that lives in all your computers.
- Notice that where you put this, (as long as is in a share-drive space) doesn’t matter and it doesn’t have to be shared with others. Different co-authors may have different projects, this file is just for you.
- For example, in my Dropbox folder, I have it under a folder I created called “1_GeneralCode”.
- Once you created and put it in a particular folder, go back to step 1 and uncomment the line “run” and make sure the file path for running the ado file is correct.
- Now in you stata_profile.do file, you will put the following
set varabbrev on
set seed 1235456
* Seed is for getting the same random number
*=======================
* Project Title
* =======================
capture program drop projectname
program define projectname
global root "$dropbox/1_Research/Project Name"
global data "$root/analysis/data"
global figures "$root/analysis/results/figures"
global tables "$root/analysis/results/tables"
global scripts "$root/analysis/scripts"
global paper "$root/paper"
global paper_figures "$root/paper/figures"
global paper_tables "$root/paper/tables"
end
This is an example of the structure of a given project. This is the project structure I use for all my projects. This means that you should create folders that look like this structure first, but if you have a different structure, you can edit this accordingly and according to the globals you would like.
If you notice, what this is doing is created a command that loads up all your useful globals, so that you can use $tables and it’ll point out to the right folder.
Since the profile.do runs this do-file, this is what makes it work in any pc for any user.
Step 4: setting up the do-files
Now that you’ve done this steps, for any do-file of that project it should start with something like this:
*=============================
* Open Settings
*=============================
medicaidracial
adopath ++ "$root/analysis/scripts/libraries/stata"
net set ado "$root/analysis/scripts/libraries/stata"
set varabbrev on
set matsize 10000
*=============================
* Code Starts
*=============================
Where medicaidracial
is the command we’ve created for a given project. The next two lines adopath
and net set ado
do two things: (1) any command you install, it will install on that folder, and (2) any command that you have installed, it will be pulled from that same folder. Why do we do this? So that if this do-file is using a specific version of a specific command, we guarantee we are using that same version.
Step 5 (Bonus): Results by time structure
Now, in the way I like doing things is to save all the output and dating it, so I like to add this to the following start of the do-files.
*=============================
* Open Directory
*=============================
medicaidracial
adopath ++ "$root/analysis/scripts/libraries/stata"
net set ado "$root/analysis/scripts/libraries/stata"
set varabbrev on
set matsize 10000
local cur_month = month(date(c(current_date),"DMY"))
local cur_year = string(date(c(current_date),"DMY"),"%tdCY")
cap mkdir "$tables/Results_`cur_year'_`cur_month'"
cap mkdir "$figures/Results_`cur_year'_`cur_month'"
global resultst "$tables/Results_`cur_year'_`cur_month'"
global resultsf "$figures/Results_`cur_year'_`cur_month'"
*=============================
* Code Starts
*=============================
What does this do? Well it creates a folder structure like this
And so we can keep track of everything we’ve produced by the month of when we did it. This way if we want to go back to how something looked, we can refer back to the appropiate folder. I like the year and then the month, because this makes the alphabetical order coordinate with the time-order of things.