経済学書専門出版 エコノミスト社
Top書籍情報計量経済・統計ソフトウェアRATSProcedures
ファイナンス大系
リアルオプション
Excelとその応用
統計学大系
経済学大系
e-ビジネス
計量経済学
ゲーム理論
経済数学
環境問題・環境経済学
人口学講座
ナレッジマネジメント
ビジネス書
NLP理論
複雑系経済学
経営学・商学大系
マーケティング
心理学・行動科学大系
金融工学・数理ファイナンス
マクロ経済学
法情報学
企業法学講座
経営工学大系
計量経済・統計ソフトウェア
オペレーションズ・リサーチ
会計学・簿記・税務
楽しい数学
時系列分析ソフトウェア
RATS

5. Procedures


RATS procedures are subroutines of RATS instructions, similar to procedures or subroutines in Pascal and other programming languages. In effect, procedures allow you to define your own new instructions using sequences of other RATS commands.

Procedures are very useful for simplifying various kinds of repetitive tasks, particularly situations where you want to apply a sequence of instructions to several different models or variables. They are also helpful when writing programs that will be used by others, as the end user only needs to learn a single "instruction" to use the procedure.

Each copy of RATS ships with about 30 pre-written procedures, including procedures for estimating and forecasting ARIMA models, doing unit-root tests, and a variety of spectral analysis techniques. These can also serve as helpful examples if you decide to write your own procedures. Many other procedures, mostly written by other RATS users, are available for downloading from our Web site or dial-up BBS.


Writing Your Own Procedures
We'll demonstrate by writing a short procedure that implements the ARCH test example discussed in the RATS Basics: Hypothesis Testing section. Here is the original example:

LINREG Y / RESIDS
# CONSTANT X1 X2 X3 X4
SET RESSQR = RESIDS**2
LINREG(NOPRINT) RESSQR
# CONSTANT RESSQR{1}
COMPUTE TEST_STAT = %NOBS*%RSQUARED
CDF CHISQR TEST_STAT 1

And here is the same test in the form of a simple procedure (the lines beginning with an "*" are comment lines):

PROCEDURE ARCHTEST DEPVAR START END
TYPE SERIES DEPVAR
TYPE INTEGER START END
LOCAL VECTOR[INTEGERS] REGLIST
LOCAL SERIES RESIDS RESSQR
LOCAL REAL TEST_STAT
*
ENTER(VARYING) REGLIST
LINREG DEPVAR START END RESIDS
# REGLIST
SET RESSQR = RESIDS**2
LINREG(NOPRINT) RESSQR
# CONSTANT RESSQR{1}
COMPUTE TEST_STAT = %NOBS*%RSQUARED
CDF CHISQR TEST_STAT 1
*
END PROCEDURE

Suppose we've saved this procedure in a file called ARCH.SRC. The program below reads in some data, reads in the procedure from the ARCH.SRC, and applies the test to several different models (the @ sign is used to execute a procedure):


CALENDAR(DAILY) 1995 1 2
ALL 1996:1:31
OPEN DATA DATA.WKS
DATA(FOR=WKS,ORG=OBS) / Y1 Y2 X1 X2 X3 X4
SOURCE ARCH.SRC
@ARCHTEST Y1
# CONSTANT X1 X2 X3 X4
@ARCHTEST Y1
# CONSTANT X1 X2
@ARCHTEST Y2
# CONSTANT X1 X2 X3


As you can see, writing this test as a procedure allows us to easily use it repeatedly with a minimum of effort.


→5.1 The End


←RATSのTopページに戻る