

The above code specifies the entire directory where datasets ‘data1.dta’ and ‘data2.dta’ are stored. For example: use “E:\\Stata\Project1\data1.dta”, clear merge 1:1 symbol using “E:\\Stata\Project1\example\data2.dta”

Absolute paths are those paths that give the exact location of a file. To understand relative paths, let’s first understand absolute paths. Also add a date and author name if it is to be used by multiple people.

Specify a project title, its description and all the datasets used in the file. Add a HeaderĪlways add a header to your do file to indicate what the do file’s purpose is. A versioncommand written at the start of the do file will make the execution of any code smooth regardless of which new Stata version you are running it on. This is especially a good idea in hindsight because you may want to execute an older do file months (or years) later with a new version of Stata but you may not remember which version of Stata you wrote that command in. Your commands will then be executed as they would have been in the older version of Stata. If you want to use a command from an older version, the version command will let you use it in a newer version. Some commands (or their syntax) are specific to older versions of Stata and are not supported by newer versions. If you wish for this to be version 13 of Stata, simply type: version 13 This lets Stata know which version it should base its interpretation of your command on. log file, just select the Stata Log option under the “File Format” menu in the dialogue box.Download Do File The do file should always start with the version command This file format will allow you to open your log file in other programs and may be easier to manage than the. This will allow you to open the log file in Stata, but other programs will not read this type of file. The default in Stata is to save the file with the extension. To create a log file, go to “File” -> “Log” -> “Begin.” This will bring up a dialogue box where you will save your log file. This will also retain your commands, although it will not save them in the same way a do-file does (they will be embedded in the output). This is called a log file and can be helpful for you to save all of your output. In addition to recording all of your commands in a do-file, you can also have Stata create a copy of everything that is sent to the Results window, with the exception of graphs. To save your do-file, you can either use the icon on the toolbar or use the “File”->”Save As” menu while the do-file editor is active. When I am ready to run the analyses, I select the commands I would like to run (you don’t have to select any text if you want to run them all) and click on the last icon on the toolbar in the do-file window: That tells Stata that the next line is part of the same command. If you have a long command that you need on separate lines, add /// at the end of each line. Within this file, Stata will assume that each line is a new command unless you tell it otherwise. use relate.dta, clearĪfter I specify the data file, I enter the rest of the commands I want to run. This is to clear any data that Stata is currently working with. Notice that on the end of each command, I add the option clear. Here are three examples of the use command, one from a data set in the current working directly, one from the internet and one from a jump drive in a different working directory. If the file is not in the working directory that you are currently in, just specify which directory you want to pull the file from. The first command you will need is the use command to specify the file you want Stata to use.
