How to use relative paths in Stata

Run Stata from your project folder so your do-file's relative paths work unchanged on your own computer and on LINCOMM.

This guide shows you how to write a Stata do-file whose file paths keep working when you move it between your own computer and LINCOMM (Linux Community Servers). Stata is the easiest package for this: it reads relative paths from the current working directory, so the trick is simply to run Stata from your project folder. For the concept behind this, see Understanding relative paths.

Prerequisites

  • A Stata do-file and its data files, kept together in one project folder.

Steps

  1. Lay out your project so the data sits in a known place relative to the do-file:

    myproject/
      analysis.do
      data/
        survey.xlsx
  2. In analysis.do, refer to data with paths relative to the project folder — no drive letters, no /mnt/...:

    import excel "data/survey.xlsx", sheet("Sheet1") firstrow

    Use .. to go up a folder. For example, to read a file from a shared folder that sits next to your project:

    import excel "../shared/regions.xlsx", firstrow
  3. On LINCOMM, move into the project folder before launching Stata, so the working directory matches your relative paths:

    cd /mnt/aae/users/jdoe/myproject
    stata -b do analysis.do

    The cd here is the Linux command that sets your working folder; stata -b do then runs the do-file from that folder.

Verify it worked

Copy the whole myproject folder to LINCOMM, change into it, and run the do-file:

cd /mnt/aae/users/jdoe/myproject
stata -b do analysis.do

It should load survey.xlsx and run without any path edits. Check analysis.log in the same folder to confirm the data loaded.

If something went wrong

  • "file ... could not be opened": You're probably running Stata from the wrong folder. Run cd into the project folder first, then start Stata. Stata reads relative paths from wherever it was launched.
  • Works on your computer but not on LINCOMM: Check that the data folder was copied along with the do-file, and that names match exactly (Linux is case-sensitive, so Data and data are different).

Download sample Stata files



Keywords:
how-to, stata, relative paths, do file, lincomm, portability 
Doc ID:
161489
Owned by:
Eric D. in Agricultural & Applied Economics
Created:
2026-05-21
Updated:
2026-05-21
Sites:
Agricultural & Applied Economics