jungsee的个人博客分享 http://blog.sciencenet.cn/u/jungsee

博文

RATS的一个示例

已有 3092 次阅读 2015-1-21 13:19 |个人分类:RATS|系统分类:教学心得

Data and code file : click here card.raw   2SLS with exogeneity test.PRG to download

*

* Wooldridge, "Econometrics of Cross Section and Panel Data", 2nd ed.

* Example 6.2 from pp 133-134.

*

* Note: The sample data files include all required data transformations.

* However, in many cases we show how these data transformations would be

* created in RATS from the basic data, as this is something you will

* need to know how to do in practice.

*

open data card.raw

data(format=free,org=columns) 1 3010 $

id nearc2 nearc4 educ age fatheduc motheduc weight $

momdad14 sinmom14 step14 reg661 reg662 reg663 reg664 reg665 $

reg666 reg667 reg668 reg669 south66 black smsa south $

smsa66 wage enroll kww iq married libcrd14 exper $

lwage expersq

*

set lwage      = log(wage)

set expersq    = exper^2

set black_educ = black*educ

*

* Run linear regression. (The description in the text should have

* included "south" in the list of explanatory variables).

*

linreg lwage

# constant educ black_educ black exper expersq smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668

*

set black_nearc4 = black*nearc4

*

* Run the linear regressions of the two potentially endogenous variables

* on the instruments. Save the residuals.

*

linreg educ / eresids

# constant exper expersq black smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668 nearc4 black_nearc4

linreg black_educ / beresids

# constant exper expersq black smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668 nearc4 black_nearc4

*

* Rerun the LINREG for lwage, including the two residuals. Test the joint

* significance of the residuals.

*

linreg lwage

# constant educ black_educ black exper expersq smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668 eresids beresids

exclude

# eresids beresids

*

*  Do the 2SLS estimates

*

instruments constant exper expersq black smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668 nearc4 black_nearc4

linreg(instruments) lwage

# constant educ black_educ black exper expersq smsa smsa66 south $

 reg661 reg662 reg663 reg664 reg665 reg666 reg667 reg668


http://www.brynmawr.edu/economics/ross/econometrics/rats.html


Economics 304:
Econometrics
Dr. John A. Del Roccili
Bryn Mawr College

DAVID ROSS ON WORKING WITH RATS

RATS is a powerful and flexible program. There are several different ways of working with it. Manuals are available in the Thomas and Guild Computer Labs and RATS has a reasonably good on line help program. To make it easier for us to help one another (provide support), I ask you to follow these general procedures, which may differ from what you did in Econ 203 or what you will choose to do in your later work.

1) Double click on the WinRATS-32 icon in the Applications folder. You will find yourself in a window called NONAME00.PRG. The {io} indicates that initially RATS expects to receive input commands from and direct output to this window.

2) Choose Directory on the File menu. Type in the directory where you are storing your data, e.g., a:.

3) Set up your three RATS windows: One containing the program with all of the RATS commands you need to complete your analysis; a working window where you will debug your program and do exploratory analysis; and a window containing the output from the finished program.

a) Choose Save As on the File menu. Type in an appropriate name for your *.LOG file -- e.g., class05.log

b) Create your program file. Since RATS programs share many common elements, the easiest way to create a program is to edit an existing program. Choose Open on the File menu and find a *.PRG file to use as your starting point -- or choose New on the File menu and paste in the program. Choose Save As on the File menu. Type in the appropriate name for your new *.PRG file. In this case, we'll use class05.prg.

c) Choose New on the File menu, then Save As. Type in the appropriate name for your *.OUT file.

4) The foremost window is the Active Window. There are a variety of ways to move among windows. If you followed the procedure so far, your *.PRG and *.OUT windows are set up for Edit Only, while your *.LOG window is ready for input and output. This is indicated by the {io} following the file name for this window. The program expects to receive commands from this window and to type results to that window. This can be changed later.

5) Select the *.PRG window. Edit the program to carry out the tasks you have in mind. (It is good practice to save the contents of each of your windows periodically to avoid the consequences of a computer crash.)

6) Highlight part or all of your program, and choose Copy on the Edit menu. Select the *.LOG window, choose Paste on the Edit menu.

7) Highlight the set of commands you wish to execute first and hit Enter. RATS will attempt to execute each command in turn. So long as i appears in brackets in the Window name, RATS will attempt to execute whatever you enter in the window. If you wish to edit the *.LOG file without executing commands, click on the R/L icon, which switches from Ready mode to Local mode. Click again to begin executing commands again.

8) Locating and correcting errors are the most frustrating parts of working with econometrics software. Typing mistakes are the most common source of errors. RATS can be extremely sensitive to where blank spaces occur in command lines. If the error isn't obvious, go back to the first line in the group you highlighted. Execute each line until you get the error.

If the error involves accessing the data, you will need to choose Clear Program on the File menu before you execute your program again. Make sure the data file is located in the default directory. It may make sense to close your *.LOG window and create a new version using commands from the *.PRG window.

Take breaks, enjoy a hot shower, have a bite to eat. Don't spend too much timing sitting in front of a recalcitrant computer. If you email me a copy of your *.LOG file as a Eudora attachment, I may be able to locate an error you can't find.

9) When, hurrah, you have eliminated errors, edit your *.PRG file to incorporate the changes you have made.

10) Go to the *.OUT window. Choose Use for Output on the Window menu. Go to the *.PRG window. Choose Use for Input on the Window menu. Choose Clear Program on the File Menu to clear your previous work from memory. Highlight the entire program and hit Enter. Select the *.OUT window to examine your output.

11) Exit RATS by choosing Exit on the file menu. Remember to save your files, although the *.LOG file is now expendable.

12) You can work with your files in any word processor. Should you wish to print any of your files while in RATS: Go to the appropriate window, choose Print on the File menu.



https://estima.com/tour/rats_basics__reading_in_d.shtml


RATS Basics: Reading in Data

Now we need to read our data from a disk file into memory. We can do that with the OPEN DATA instruction (which tells RATS which file you want to read) and the DATA instruction (which actually reads the data), or by using one of the Data Wizards.

 

If you already know the name and format of the file, you may find it easiest to type in the commands yourself.

 

Otherwise, you may find it more convenient to use the Data Wizard.

 

The Data Wizards

If you are reading data from a file in our own "RATS" format, you start by doing File--Open RATSData to open the file. RATS will display a list of all the series in the file. From this window, you can use mouse clicks as well as menu and toolbar operations to view or edit the series, graph them, or compute basic statistics. You then select (highlight) the series you want to read and select Data Wizard (RATS Format) from the Wizards menu.

If your file is another format, such as an Excel spreadsheet, you start by selecting Data Wizard (Other Formats) from the Wizards menu. You then use dialog boxes to select the your data file, confirm or set the frequency and start date (which RATS will try to determine from the information on the file), and read in the data.

 

Our Example Program

After using the Data Wizard or typing in the appropriate OPEN DATA and DATA instructions, our example program will look something like this:

 

CALENDAR 1922

ALLOCATE 1941:1

OPEN DATA C:RATSFOODDATA.RAT

DATA(FORMAT=RATS) / FOODCONS PRRETAIL DISPINC FOODPROD PRFARM

 

In this case, our data is stored on a RATS format file called FOODDATA.RAT, located in the directory C:RATS. The FORMAT option on the DATA instruction tells RATS the format of the file. The "/" tells RATS to read all the data on the file, and this is followed by the list of series we want to read in (FOODCONS, PRRETAIL, etc.). You can actually omit this list if you just want RATS to read all the series on the file.

 

Other File Formats

RATS format is specially designed to handle time series data. You may find it convenient to convert your data to RATS format, but it's certainly not required, because RATS can read data directly from many other types of files, including Excel spreadsheets, various types of text files, and dBase files. You can also read data directly from Haver Analytics (www.haver.com) databases. The Professional version of RATS can even read and write FAME format data bases (see www.fame.com).

 

Converting Data Frequencies

The DATA instruction provides many options for automatically converting data from a higher frequency to a lower frequency, including taking averages, sums, or geometric means, or selecting particular subperiods. For example, you could convert monthly data to quarterly data by taking averages, or by taking the value of the third month of each quarter. RATS also includes two procedures for interpolating low frequency data to a higher frequency.

 

Next: RATS Basics: Examining the Data

 

Back to the Table of Contents

 

 





https://blog.sciencenet.cn/blog-793574-861502.html

上一篇:WinRats时间序列软件(比EVIEWS好,个人觉得)
下一篇:文献阅读(Calling Recessions in Real Time-James D. Hamilton
收藏 IP: 111.203.16.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-16 19:26

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部