Stata: Saving and using user-written commands - Tutorial

This document helps guide you through the process of saving and using user-written commands when on the remote desktop version of Stata.

There are a lot of sophisticated Stata users who program functions and publish them to make life easier for the rest of us. We make extensive use of them in this course. But for good reasons, the university doesn’t want us messing around with their system by installing all sorts of programs that they haven’t vetted. So, we need a workaround. This document demonstrates that workaround. I have posted a video about how to do this on Learn. It assumes that you have already set up OneDrive.

Create a folder in OneDrive to save command files to (one-time):

 In your university OneDrive account, create a folder that is dedicated only to saving Stata command files. To do this, open up OneDrive, right-click, then go to New, then Folder. Give it a name. I used “Owen_Stata_commands”. It looks like this:

OneDrive folder, stata sub-folder

Tell Stata to use that folder (every time):

Now that the folder is set up in a place that we have access to, we just need to tell Stata to both save command files there and to look there when we try to run commands.

First, you need to know what the path name for that folder is. You can find that by right-clicking on the folder and then click “Properties”. It will look like this:

Owen_Stata_commands properties, general tab

You just need to put #1 and #2 together (separated by a backslash) to get the path name. Mine is:

 “C:\Users\acocoop4\OneDrive - University of Waterloo\Owen_Stata_commands”

 Next, you need to tell Stata to include that folder in the places that it looks. Customize and run (either in the command box or from a do file) the following using your own path name:

 sysdir set PERSONAL “C:\Users\acocoop4\OneDrive - University of Waterloo\Owen_Stata_commands”

A few points:

  • “PERSONAL” needs to be in caps

  • this should all be on one line

  • make sure you put quotations around the path name

Finally, you need to tell Stata to save any commands that you download from the internet to that location. This does it:

net set ado PERSONAL

Do not alter that command in any way. It works as is.

Take home message

Once you set up the OneDrive folder, just get in the habit of running the two commands below every time you log onto Stata (the first one will be slightly different for each person):

sysdir set PERSONAL “C:\Users\acocoop4\OneDrive - University of Waterloo\Owen_Stata_commands”

net set ado PERSONAL

Video Tutorial