Understanding relative paths
A relative path is a way of pointing to a file in relation to your code, instead of spelling out its full location on one specific computer. Using relative paths is what lets you write a script on your own computer and run it unchanged on LINCOMM (Linux Community Servers). This page explains the idea and why each statistics package handles it a little differently.
The problem this solves
An absolute path lists a file's entire location, starting from the top of the drive:
C:\Users\jdoe\Documents\project\data.csv(Windows)/mnt/aae/users/jdoe/project/data.csv(LINCOMM)
Absolute paths break the moment your code moves. The path above works on your Windows laptop but means nothing on LINCOMM, and vice versa. If you share your project with a colleague, their path is different again. Every move means hand-editing paths — tedious and easy to get wrong. This is also why absolute paths cause trouble in version control systems such as Git, where the same code runs on many machines.
How it works
A relative path starts from a known anchor — usually your script or your project folder — and describes how to get to the file from there. Two symbols do most of the work:
subfolder/data.csv— a file inside a folder next to the anchor.../data.csv—..means "go up one folder," so this is a file in the parent folder.
So if your project is laid out like this:
myproject/
analysis script
data/
transactions.csv
your code can refer to the data as data/transactions.csv. Copy the whole myproject folder anywhere — your laptop, a colleague's machine, or LINCOMM — and that reference still points to the right file. Nothing to edit.
Why each package is different
The catch is the anchor: each tool decides differently where a relative path starts from. That single difference is why the how-to steps vary by language.
| Package | Anchor for relative paths | What this means for you |
|---|---|---|
| Stata | The current working directory (where Stata is running from) | Easiest. Run Stata from your project folder and relative paths just work. |
| Python | Whatever you anchor to — usually the script's own location | Anchor paths to the script file once, and you can run it from anywhere. |
| R | The current working directory; R has no built-in idea of "this script's folder" | Trickiest. You set the anchor yourself, either from the script or by setting the working directory. |
The package-specific guides show the exact code for each.
Limitations and trade-offs
- Relative paths depend on a consistent folder layout. If you move just the script and leave its data behind, the relative path breaks. Keep a project's files together and move them together.
- The anchor has to be predictable. Most problems come from running code from an unexpected folder, so the anchor isn't where you assumed.
- Some data isn't part of your project — for example, a large shared dataset on the Research Drive at
/mnt/rdrive/<PI netid>. It's reasonable to reference that by absolute path on purpose, since it isn't meant to travel with your code.