Stata profile.do: nice tips
Each time you start a new Stata session, Stata looks for two files, sysprofile.do and profile.do. If these files are found, Stata executes their contents. This post is about how to modify profile.do, in which you can put anything you want Stata to do before you start working with it.
From time to time, I upload my profile.do into my GitHub repository (randrescastaneda/Stata_profile), so you can check it out and download it for your own purposes. Alternatively, I provide my current version below (April, 2019), and a short explanation of what it does.
First, I set up some Stata parameters such as the default scheme of by graphs, the fonts, and the display formatting of the results window.
Second, change the behavior of the F keys in my keyboard. In my case, I like to work with the command pause for debugging my ado-files, so I modify F2 to execute end and F9 to execute BREAK. I also use F5 and F6 to change my current directory.
Third, I set some globals that are either necessary for other programs or for my own work. Then, I open some programs that I use while working in Stata. In particular, I use Total Commander for file management and NotePad++ for editing my Stata scripts. In my post My Stata editor: NotePad++ I explain the features of this amazing text editor.
Fifth, I make a rule for setting the current directory depending on whether or not I am connected to the intranet of my job. Finally, I set all the different adopaths of the ado-files in which I contribute in Github or bare repositories internally in my job. I explain this final procedure in my post Working with GitHub and Stata.
I found this post very interesting in Statalist.org about useful tips for the profile.do.
/*===========================================================================
project: profile
Author: Andres Castaneda
---------------------------------------------------------------------------
Creation Date: September 2, 2014
===========================================================================*/
/*==============================================================================
Program set up
==============================================================================*/
set matsize 2000
set more off, permanently
set r on, permanently // display execution time
set scheme plotplainblind, permanently // nice scheme for graphs available in ssc
graph set window fontface "Times New Roman" // font for graphs
set checksum off, permanently // to clean api queries
set tracenumber on, permanently // numbers on trace
set tracedepth 3
/*==============================================================================
shortcuts
==============================================================================*/
global F2 `"end;"' // to work with pause
global F4 `"disp _dup(20) "-" "End of section" _dup(20) "-" _n(200) _dup(20) "-" "New section" _dup(20) "-";"'
global F5 `"cd "c:\Users\wb384996\OneDrive - WBG\temp\stata";"' // cd 1
global F6 `"cd "x:\01.personal\wb384996\temporal\stata";"' // cd 2 on network drive
global F9 `"BREAK;"' // working with pause
/*==============================================================================
Globals
==============================================================================*/
global google_api "" // store my api keys
* interaction with R
global Rterm_path `"c:\Program Files\R\R-3.4.0\bin\x64\Rterm.exe"'
global Rterm_options `"--vanilla"'
/*==============================================================================
Open Important programs
==============================================================================*/
winexec "C:\Users\wb384996\Documents\Totalcmd\TOTALCMD64.EXE" // start total commander
sleep 5000
winexec "C:\Program Files\Notepad++\notepad++.exe" // start notepad ++
global MYEDITOR winexec notepad++
/*==============================================================================
Current directory depending on my Internet connection
==============================================================================*/
cap cd "x:\01.personal\wb384996\temporal\stata"
if (_rc) {
disp in g "you're not connected to the intranet." _n ///
"Current directory set to:" _n ///
in y "c:\Users\wb384996\OneDrive - WBG\temp\stata\"
cd "c:\Users\wb384996\OneDrive - WBG\temp\stata\"
}
/*==============================================================================
Working directories in GitHub
==============================================================================*/
* set adopaths for working with Github and Git
local adodir1 "c:\Users\wb384996\OneDrive - WBG\GTSD\02.core_team\01.programs\01.ado"
local adodir2 "c:\Users\wb384996\OneDrive - WBG\ado\github_contr"
local adodir3 "c:\Users\wb384996\OneDrive - WBG\ado\myados"
local i = 1
while ("`adodir`i''" != "") {
local adodirs `"`adodirs' "`adodir`i''" "'
local ++i
}
foreach adodir of local adodirs {
local dirs: dir "`adodir'" dir "*"
gettoken dir dirs : dirs
while ("`dir'" != "") {
local files ""
if regexm("`dir'", "^\.git|^_") {
gettoken dir dirs : dirs
continue
}
local ados: dir "`adodir'/`dir'" files "*.ado"
local help: dir "`adodir'/`dir'" files "*.sthlp"
local files = `"`ados'`help'"'
if (`"`files'"' != "") {
qui adopath ++ "`adodir'/`dir'"
disp "`adodir'/`dir'"
}
local subdirs: dir "`adodir'/`dir'" dir "*"
if (`"`subdirs'"' != "") {
foreach subdir of local subdirs {
if regexm("`subdir'", "^\.git|^_") continue
local dirs "`dirs' `dir'/`subdir'"
}
}
gettoken dir dirs : dirs
}
}
exit
/* End of do-file */