Managing multiple editors in STATA:

For this week’s blog post, it seems useful to cover some code I’ve learned for Stata.  This first useful trick allows multiple users who are going to use the same dofile to run that file without having to first customize the filepath code.  By copying the individual usernames and filepaths and stringing them together with an “else if”, this code will work for each user.  This will only work if all of the users are operating off a common root file nested in a cloud drive like Google Drive.  After the initial filepath location is entered here, global path locations are set to correspond to locations within the Google Drive.  This helps make a quick reference to a document in a particular file or to allow Stata to auto-store output files(discussed later).  Using the code “gl” followed by the intended nickname of the folder, we can direct the nickname to refer to a specific end point in a subfolder.  For example: gl raw “raw_data” directs the computer to search for a file in “raw_data” folder located in the Google Drive specified in the filepath command earlier.

Figure A

After the global path locations are set, they can be referenced later. For example, the “use ‘dataset’” command at the bottom of Figure A, directs the user’s computer to search for the file  that corresponds to “raw” by adding a dollar sign ($) in front of the word “raw”.  Then add a backslash (\) between the global filepath name and the actual dataset name.  One thing to note here is that mac users will have to change the backslash (\) to a forward slash (/) in the filepath location use command.

The second useful set of commands allows the user to export graphs to a previously set global location by simply running the dofile.  In this case, we had a histogram export to the file path specified for reporting documents in the global commands set up in Figure A.  The command “graph export” sends a graphic image to a location and the dollar sign ($) specifies the global filepath.  Then the file type is specified as png and we replace any existing version of that file.

Figure B

Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.