ECON3208: A Brief Guide to Using STATA

ECON3208: A Brief Guide to Using STATA

For Applied Econometric Methods, data are usually stored in files with a “ .dta” suffix (a STATA-specific format). We use a do-file (with .do suffix), which contains a set of STATA commands, to instruct STATA to read in data and carry out desired computations. You may download data files and do-files from our website.

1.   Make a new folder, say E:\AEM, in your USB drive. Download dta-files and do-files into E:\AEM.

For instance, you have the files bwght_1st.do and bwght.dta in this folder.

2.   Launch STATA by clicking on the STATA icon in your Desktop.

3.   Open the Do-File Editor by pressing Ctrl+9 (or clicking on  in STATA toolbar). Open the do- file bwght_1st.do via File > Open > File > E:\AEM

Change E:\AEM in the 5th line to your USB folder created in Step 1 if it differs from E:\AEM. For example, if your USB drive is identified as G and you named the folder in Step 1 as myData, then the 5th line E:\AEM should be replaced by G:\myData.

4.   Execute the commands in the do-file bwght_1st.do by pressing Ctrl+D (or clicking on  in

the Do-Editor toolbar). The outcome shows up in the Result window and two graph windows.

5.   In the Do-File Editor, we create and modify the do-files to carryout various data analysis tasks (save your do-files!). The commands in the do-files can also be executed by typing them in the Command   window of STATA.

6.   Once the do-file is correctly executed, you can inspect data by clicking on  in STATA toolbar.

7.   Note the following points.

- A do-file (ie, “.do” file) contains a collection of Stata commands for specific tasks.

- Commands in a do-file usually occupies one line.

- If one command is too long, it can be folded in several lines using the “///” .

- A do-file maybe created, modified and saved by the Do-File Editor.

- Once a do-file is run, the results or error messages show up in the Results window (in red).

- The output must be carefully checked for errors.

- If there are errors, the do-file must be corrected andre-run.

8.   Some useful STATA commands:

/* and */ : whatever (usually comments) between /* and */ are ignored by STATA

// : whatever after // in a line are ignored by STATA

/// : indicate that the line to be continued

version 9 : compatible with Stata Version 9 or newer

clear : clear things from previous runs

set more off : display output all at once (rather than one screen at a time)

cd : define work folder (cd means  “change directory”)

describe : data description (including variable definiteions)

summarize : produce descriptive statistics

graph twoway (scatter y x) : produce scatter plot y versus x

histogram y : produce histogram of y

regress y x : regressing y on x (OLS)

log my.log, replace : save results in the file “my.log”, replace old results

log close : close the log file “my.log”

exit : stop execution

9.   Explore STATA by looking into Help > Contents in STATA menu. You can also type help in the Command window. If you want help for regress, you may type help regress in the Command window.

10. To do the computation exercises in the Tutorial Program, you may try to write your own do-files by  consulting the similar sample do-files on our website. The practice will help you to write do-files for your assignments and course project.

发表评论

电子邮件地址不会被公开。 必填项已用*标注