Preamble when switching between OS X and Windows

A problem when working on one and the same project on different platforms (here: Windows and Mac/OS X) is that path-names differ. There are two straightforward solutions to this:

1) When defining a number of different path (e.g. one path where data is stored, one where results/output is stored), it is handy to define the paths as globals and to add an “if” condition. The platform can be detected by the local `c(os)’:

if c(os) == "MacOSX" {
	global datafiles="/Volumes/projects/YOUR_DATA_FOLDER_OSX/"

if c(os) == "Windows" {
	global datafiles="C:\YOUR_DATA_FOLDER_WINDOWS\"

The data can be called by the following command (on either platform)

use "$datafiles/data.dta", clear

2) If there is just one folder to call, this can be arranged by changing the directory in the beginning of the do-file:

cap cd "C:\YOUR_DATA_FOLDER_WINDOWS\" cap cd "/Volumes/projects/YOUR_DATA_FOLDER_OSX/" use data.dta

This will call your data in the right folder on either platform

Leave a Reply