Stata TutorialThis is a basic introduction to Stata. In this module we will cover Stata's user interface, getting help, installing "STB" programs and updating Stata, how to "use" data, and "do" and "log" files. The next modules in this tutorial are:
Stata's user interfaceWhen you first open Stata, the window is rather small. You can, of course make the windows larger, but the type remains small. You can change the fonts as well by clicking on the window icon in the top left corner of any of the Stata windows. Stata, by default opens with four windows:
There are three other windows in Stata:
Getting Help in StataThere are several ways of getting help in Stata. The first, of course, is the "help" command. You can enter the help command from the Command window and the help text will be displayed in the Results window. Or, you can use the "Stata command" option in the Help menu and the help text will be displayed in the Viewer window. The "help" command is good only if you know the command for which you want help. If you do not know the command, then you should use the "search" command which actually does a keyword search of Stata documentation. The search command (or help menu option) has two versions: one which limits the search to your computer and one which searches Stata's website. Of course, you must be connected to the Internet to search the website ("Search net resources"), and if you are, this is the better choice. Often when you use the search or help in Stata you will find commands that do exactly what you want, but when you try to use them on your own computer, you get an "unrecognized command" error. That is because many commands in Stata have been written by other Stata users and are not part of "official" Stata. These are often referred to as the "STB" (Stata Technical Bulletin) or "User-written" programs and you must install these commands yourself. Stata makes this very easy as you can just click your way through various menus in the viewer. Every two months Stata releases an update. This update adds functionality to Stata as well as fixing bugs that may have been found since the previous update was released. You can update Stata by simply selecting the "Official Updates" option under the "Help" menu and following the instructions. Using DataStata wouldn't be of much use unless you had some data to analyze. There are several ways of getting data into Stata, but the easiest is the "use" command. The "use" command is only for data that are already in Stata format (as opposed to text, "raw" or Excel). To get data into Stata, you simply need to give the command "use mydata" where we assume the name of your data file is "mydata.dta". You can also "use" data that are stored somewhere on the Internet by simply using the URL and the filename. When you are done, you must save your data and you do this with the "save" command. If you have made many changes to your data, then you will either need to specify a new name for the file or include the "replace" option. Stata is pretty good about not letting you shoot yourself in the foot, but it is not foolproof. Do, Log and Cmdlog filesThere are two cardinal rules when working with Stata:
Having a do-file is the only way to make sure that you can reproduce your results at a later time! They are a record of what you did and why (assuming you added plenty of comments). Log files also are a record of what you did, but they also contain the results of what you did. It wouldn't make much sense to spend several hours analyzing data and not keep the results, now would it? A command log, or "cmdlog" is a record of ONLY the commands you execute and is especially important if you use the pull-down menus to do your work. You can start a do-file by simply clicking on the do-file editor button. Make sure that the "Auto indent" and "Auto save on do/run" options are checked in the Edit>Preferences menu. You can enter any valid Stata command in the editor and click on "Run" to run all of the commands. You can even highlight one or more commands to run only those commands. You can start a log file with the command "log using mylog.log". When you use ".log" as the extension, Stata automatically creates the log as a plain text file that can then be opened in MSWord or notepad as well as Stata's viewer. Everything you see in the Results window goes into the log with the exception of output from the "help" command and graphs created with the "graph" command. When you are done, you can close the log with the "log close" command. You can start a command log with the command "cmdlog using mycmdlog.log". Like regular logs, using the ".log" extension makes sure the file is in text format. As mentioned above, this file has only the commands you execute, no output. Additionally, all commands, whether they are issued from the command window, pull-down menus, or a do-file are recorded in the command log. You close the command log with the command "cmdlog close". On to the next tutorial, Reading and Documenting Data
|


